#include "mainwindow.h"
#include "ui_mainwindow.h"
#define CAMERA_OFF_TIMER   3000   //最大空闲时间
extern bool WinShowFlag;
extern QString USER;
extern QString USERTYPE;
QString CARNO;
QString CARINTIME;
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    init();

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::init()
{
    //界面设置
    init_textBrowser();
    this->initPaint();
    //web
    this->initWeb();
    //初始化车牌识别摄像机连接
    this->initCamera();
    //定时器
    this->initTimer();
    //文件操作
    this->initFile();
}

void MainWindow::init_Status(park_status *info)
{
    QString data;
    data=QString("总车位:%1\r\n").arg(info->AllCarNum);
    data.append(QString("空闲车位:%1\r\n").arg(info->FreeCarNum));
    data.append(QString("当班入场:%1\r\n").arg(info->InCarNum));
    data.append(QString("当班出场:%1").arg(info->OutCarNum));
    ui->textBrowser_Status->setText(data);
}

void MainWindow::init_Shift(park_shift *info)
{
    QString data;
    data=QString("操作员:%1\r\n").arg(info->User);
    data.append(QString("登陆:%1\r\n").arg(info->ParkTime));
    data.append(QString("收费车辆:%1\r\n").arg(info->CarNum));
    data.append(QString("收费金额:%1").arg(info->Money));
    ui->textBrowser_Shift->setText(data);
}


void MainWindow::init_textBrowser()
{
    isListFreeOpen=false;
    WinShowFlag=false;
    // ui->listWidget_FreeFee->setVisible(false);
    ui->stackedWidget_FeeShow->setCurrentIndex(0);
    connect(ui->pushButton_FreeTime,SIGNAL(clicked()),this,SLOT(ListShow()));
    connect(ui->pushButton_TurnShift,SIGNAL(clicked()),this,SLOT(TurnClass()));
    connect(ui->pushButton_Set,SIGNAL(clicked()),this,SLOT(SysSlot()));
    connect(ui->pushButton_Record,SIGNAL(clicked()),this,SLOT(SearchSlot()));
    connect(ui->toolButton_CarInPark,SIGNAL(clicked()),this,SLOT(CarInSlot()));
    connect(ui->toolButton_ParkInBack,SIGNAL(clicked()),this,SLOT(WindowSlot()));
    connect(ui->toolButton_SearchBack,SIGNAL(clicked()),this,SLOT(WindowSlot()));
    connect(ui->toolButton_back,SIGNAL(clicked()),this,SLOT(WindowSlot()));
    /*查询*/
    connect(ui->toolButton_SearchCar,SIGNAL(clicked()),this,SLOT(SearchCarSlot()));
    connect(ui->toolButton_SearchRecord,SIGNAL(clicked()),this,SLOT(SearchRecordSlot()));
    connect(ui->toolButton_SearchFeeRecord,SIGNAL(clicked()),this,SLOT(SearchFeeSlot()));
    /*设置*/
    connect(ui->toolButton_CarManage,SIGNAL(clicked()),this,SLOT(SysCarSlot()));
    connect(ui->toolButton_SeatManage,SIGNAL(clicked()),this,SLOT(SysSeatSlot()));
    connect(ui->toolButton_FeeManage,SIGNAL(clicked()),this,SLOT(SysFeeSlot()));
    connect(ui->toolButton_UserManage,SIGNAL(clicked()),this,SLOT(SysUserSlot()));
    connect(ui->toolButton_SysManage,SIGNAL(clicked()),this,SLOT(SysSetSlot()));
    /*主界面显示*/

    connect(ui->pushButton_CarManageIn,SIGNAL(clicked()),this,SLOT(ExcleToWidgetCarManage()));
    connect(ui->pushButton_CarManageOut,SIGNAL(clicked()),this,SLOT(WidgetCarManageToExcle()));
    ui->textBrowser_Status->setAlignment(Qt::AlignLeft);
    ui->textBrowser_Shift->setAlignment(Qt::AlignLeft);
    ui->textBrowser_CarStatus->setAlignment(Qt::AlignCenter);
    statusInfo.AllCarNum="0";
    statusInfo.FreeCarNum="0";
    statusInfo.InCarNum="0";
    statusInfo.OutCarNum="0";
    init_Status(&statusInfo);

    USER="操作员";
    this->ClassTime=QDateTime::currentDateTime();

    ui->stackedWidget_Window->setCurrentIndex(0);
    /*权限*/
    ui->pushButton_Set->setVisible(false);
    //windowShow(WinShowFlag);
}

void MainWindow::initPaint()
{
    // QRegExp regExp("[A-Za-z0-9]{0,6}");
    QRegExp double_rx1000("1000|([0-9]{1,3}[\.][0-9]{1,1})");
    ui->lineEdit_FeeItem->setValidator(new QRegExpValidator(double_rx1000, ui->lineEdit_FeeItem));
    gb2312 = QTextCodec::codecForName("GB2312");
    utf8 = QTextCodec::codecForName("UTF-8");
    udpLed = new ledTcp();
    ui->label_PictureIn->installEventFilter(this);
    ui->label_PictureOut->installEventFilter(this);
    ui->label_RecordInPicture->installEventFilter(this);//通行记录入场图片
    ui->label_RecordOutPicture->installEventFilter(this);//通行记录出场图片
    ui->label_ParkInPic->installEventFilter(this);//选车出场

    ui->pushButton_carIn->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_carOut->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_OK->setFocusPolicy(Qt::NoFocus);
    tool_FeeFreeBool=true;
    ui->toolButton_FeeFreeBool->setStyleSheet(tr("border-image: url(:/images/on.png);"));
    tool_Fee24Bool=true;
    ui->toolButton_Fee24Bool->setStyleSheet(tr("border-image: url(:/images/on.png);"));
    tool_SysLinIn=true;
    ui->toolButton_SysLinIn->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    tool_SysPassTimeCar=true;
    ui->toolButton_SysPassTimeCar->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    tool_SysFeeCarOut=true;
    ui->toolButton_SysFeeCarOut->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    tool_SysPrint=true;
    ui->toolButton_SysPrint->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    tool_SysCarHan=true;
    ui->toolButton_SysCarHan->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    tool_SysFee=true;
    ui->toolButton_SysFee->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    tool_SysBack=true;
    ui->toolButton_SysBack->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    tool_SysAllCar=true;
    ui->toolButton_SysAllCar->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    tool_SysUser=true;
    ui->toolButton_SysUser->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    tool_SysSeat=true;
    ui->toolButton_SysSeat->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    tool_SysTopFee=true;
    ui->toolButton_SysTopFee->setStyleSheet(tr("border-image: url(:/images/kai.png);"));

    ui->tableWidget_Fee->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget_Fee->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidget_User->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget_User->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidget_CarManage->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget_CarManage->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidget_Seat->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget_Seat->setEditTriggers(QAbstractItemView::NoEditTriggers);
    qDebug()<<"initPaint";
}

void MainWindow::initTimer()
{
    timer_in=new QTimer(this);//入口起杠
    connect(timer_in,SIGNAL(timeout()),this,SLOT(camera_in()));//入口起杠

    timer_out=new QTimer(this);//出口起杠
    connect(timer_out,SIGNAL(timeout()),this,SLOT(camera_out()));//出口起杠

    timer_CarDown=new QTimer(this);//下载固定车线程
    connect(timer_CarDown,SIGNAL(timeout()),this,SLOT(Car_downLink()));
    //timer_CarDown->start(10000);

    timer_recordDown=new QTimer(this);//下载车辆通行记录
    connect(timer_recordDown,SIGNAL(timeout()),this,SLOT(info_downLink()));
    //timer_recordDown->start(10000);

    timer_recordup=new QTimer(this);//上传车辆通行记录
    connect(timer_recordup,SIGNAL(timeout()),this,SLOT(info_upLink()));
    //timer_recordup->start(10000);

    timer_bind_down=new QTimer(this);//下载车辆车位绑定信息
    connect(timer_bind_down,SIGNAL(timeout()),this,SLOT(seatbind_downLink()));
    //timer_bind_down->start(15000);

    timer_stall_down=new QTimer(this);//下载车位信息
    connect(timer_stall_down,SIGNAL(timeout()),this,SLOT(car_stall_downLink()));
    //timer_stall_down->start(30000);

    timer_quit_carNumberIn=new QTimer(this);//屏蔽抓拍功能
    connect(timer_quit_carNumberIn,SIGNAL(timeout()),this,SLOT(quit_carNumberIn()));
    carNumberIn_flag=true;

    timer_quit_carNumberOut=new QTimer(this);//屏蔽抓拍功能
    connect(timer_quit_carNumberOut,SIGNAL(timeout()),this,SLOT(quit_carNumberOut()));
    carNumberOut_flag=true;
    //界面显示
    this->Timer_bg= new QTimer();
    connect(Timer_bg,SIGNAL(timeout()),this,SLOT(runTimerOut()));
    this->Timer_bg->start(1000);
    qDebug()<<"initTimer";
}

void MainWindow::dispUpdata()
{
    //当无车无动态消息时，静态显示时间日期静态消息
    int seat_count;
    QString seat_num;

    displayData_t info;
    seat_count=this->myDb->select_seat_count(&this->myDb->sqlite_db);
    info.audioStr.clear();
#ifdef OLD_LED
    info.audioStr = "车牌识别  一车一杆  减速慢行";
#endif
    for(int j=0;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    info.DispelayStr[0] = "车牌识别  一车一杆  减速慢行";
    info.DispelayStr[1]="\\DL月\\DD日";
    info.DispelayStr[2] ="\\DH时\\DM分";
    //info.DispelayStr[3]=QString("空余车位%1个").arg(CAR_SEAT);

    //    if(sysInfo->park_type==4)
    //    {
    if((sysInfo->car_stall-seat_count)>0)
    {
        seat_num=QString::number(sysInfo->car_stall-seat_count) ;
    }else{
        seat_num=QString::number(0);
    }

    info.DispelayStr[3]=QString("空余车位%1个").arg(seat_num);
    //    }else{
    //        info.DispelayStr[3]=sysInfo->galleryName+"   ";
    //    }
    this->cameraIn->socket_short_display(&info);
    ui->pushButton_carIn->setText("待通行");
    timer_update->stop();
    //显示系统时间
    // receive_cuTime(QTime::currentTime());//定时删除过期车辆 信息
}

//更新显示界面
void MainWindow::dispUpdata2()   ////新增函数用于还原出口显示屏时间日期, 空位与disupdata函数入口显示屏相对应
{
    //当无车无动态消息时，静态显示时间日期静态消息
    int seat_count;
    QString seat_num;

    displayData_t info;
    ///bzero(&info,sizeof(info));
    seat_count=this->myDb->select_seat_count(&this->myDb->sqlite_db);
    info.audioStr.clear();
#ifdef OLD_LED
    info.audioStr = "车牌识别  一车一杆  减速慢行";
#endif
    for(int j=0;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    info.DispelayStr[0] = "车牌识别  一车一杆  减速慢行";
    info.DispelayStr[1]="\\DL月\\DD日";
    info.DispelayStr[2] ="\\DH时\\DM分";

    //    if(sysInfo->park_type==4)
    //    {
    if((sysInfo->car_stall-seat_count)>0)
    {
        seat_num=QString::number(sysInfo->car_stall-seat_count) ;
    }else{
        seat_num=QString::number(0);
    }
    info.DispelayStr[3]=QString("空余车位%1个").arg(seat_num);
    //    }else{
    //        info.DispelayStr[3]=sysInfo->galleryName+"   ";
    //    }
    this->cameraOut->socket_short_display(&info);
    timer_update2->stop();
    //显示系统时间
    //receive_cuTime(QTime::currentTime());//定时删除过期车辆 信息
}

void MainWindow::ListShow()
{
    if(isListFreeOpen)
    {
        isListFreeOpen=false;
        ui->stackedWidget_FeeShow->setCurrentIndex(0);
        ui->listWidget_FreeFee->clear();
        //ui->listWidget_FreeFee->setVisible(false);
        for(int i=1;i<6;i++)
        {
            ui->listWidget_FreeFee->addItem(new QListWidgetItem(QString("优惠%1元").arg(i)));
            //            ui->listWidget->setViewMode(QListView::IconMode);
            //            ui->listWidget->setIconSize(QSize(25,25));
            //            ui->listWidget->setMovement(QListView::Static);
            //            ui->listWidget->setSpacing(5);
            ui->listWidget_FreeFee->setSelectionMode(QAbstractItemView::ExtendedSelection);

        }
    }else{
        isListFreeOpen=true;
        ui->stackedWidget_FeeShow->setCurrentIndex(1);
        // ui->listWidget_FreeFee->setVisible(true);
        //  updatePosition();
        //  ui->listWidget_FreeFee->setStyleSheet("QListWidget{border: 0px; border-style:outset;color:black;background-color:rgb(0,205,0);}  QListWidget::item:selected:!active {  color:white; border-width: 0px ;  }QListWidget::item:selected:active {color:white;  border-width: 1px;  } ");
    }
}

void MainWindow::TurnClass()
{
    loginDilog= new Login(this->myDb);
    loginDilog->exec();
    windowShow(WinShowFlag);
    //scroll->move((QApplication::desktop()->width()-scroll->width())/2,(QApplication::desktop()->height()-scroll->height())/2);
}

void MainWindow::WindowSlot()
{
    CARNO.clear();
    CARINTIME.clear();
    ui->stackedWidget_Window->setCurrentIndex(0);
}

void MainWindow::CarInSlot()
{
    ui->stackedWidget_Window->setCurrentIndex(1);
    ui->label_ParkInPic->setPixmap(QPixmap(":/images/u2.png"));
    InParkPixmap=QPixmap();
}

void MainWindow::SearchSlot()
{
    ui->stackedWidget_Window->setCurrentIndex(2);
    ui->stackedWidget_Search->setCurrentIndex(0);
}

void MainWindow::SysSlot()
{
    ui->stackedWidget_Window->setCurrentIndex(3);
    ui->stackedWidget_Sys->setCurrentIndex(0);
}

void MainWindow::SearchCarSlot()
{
    ui->stackedWidget_Search->setCurrentIndex(0);
}

void MainWindow::SearchRecordSlot()
{
    ui->stackedWidget_Search->setCurrentIndex(1);
}

void MainWindow::SearchFeeSlot()
{
    ui->stackedWidget_Search->setCurrentIndex(2);
}

void MainWindow::SysCarSlot()
{
    ui->stackedWidget_Sys->setCurrentIndex(0);
    car_vehicle("","所有车");
    //   tableWidget_CarManage_Show();
}

void MainWindow::SysSeatSlot()
{
    ui->stackedWidget_Sys->setCurrentIndex(1);
    tableWidget_Seat_Show();
}

void MainWindow::SysFeeSlot()
{
    ui->stackedWidget_Sys->setCurrentIndex(2);
    feeInfo.ID.clear();
    ui->label_FeeItem->setText("请选择条目");
    ui->lineEdit_FeeItem->clear();
    //收费规则
    int m,n;
    m=ui->comboBox_FeeLinFree->findText(sysInfo->FreeTime);
    ui->comboBox_FeeLinFree->setCurrentIndex(m);
    n=ui->comboBox_FeeTanFree->findText(sysInfo->FreeTime2);
    ui->comboBox_FeeTanFree->setCurrentIndex(n);
    if(sysInfo->LoseFreeTime==0)
    {
        ui->toolButton_FeeFreeBool->setStyleSheet(tr("border-image: url(:/images/off.png);"));
        tool_FeeFreeBool=false;
    }else if(sysInfo->LoseFreeTime==1){
        ui->toolButton_FeeFreeBool->setStyleSheet(tr("border-image: url(:/images/on.png);"));
        tool_FeeFreeBool=true;
    }
    if(sysInfo->AddDayTime==0)
    {
        ui->toolButton_Fee24Bool->setStyleSheet(tr("border-image: url(:/images/off.png);"));
        tool_Fee24Bool=false;
    }else if(sysInfo->AddDayTime==1){
        ui->toolButton_Fee24Bool->setStyleSheet(tr("border-image: url(:/images/on.png);"));
        tool_Fee24Bool=true;
    }
    tableWidget_Fee_Show();
}

void MainWindow::SysUserSlot()
{
    ui->stackedWidget_Sys->setCurrentIndex(3);
    tableWidget_User_Show();
}


void MainWindow::SysSetSlot()
{
    ui->stackedWidget_Sys->setCurrentIndex(4);
    sysTemReset();
}


void MainWindow::windowShow(bool flag)
{
    if(flag)
    {
        this->ClassTime=QDateTime::currentDateTime();
        if(USERTYPE=="system")
        {
            ui->pushButton_Set->setVisible(true);

        }else{
            ui->pushButton_Set->setVisible(false);
        }
        this->Timer_bg->start(100);
    }
}

void MainWindow::initWeb()
{
    this->myDb = new datebase();
    TurnClassTime=QDateTime::currentDateTime();//换班时间

    my_network=new network(this->myDb);
    down_network = new Car_Product(this->myDb);

    connect(down_network,SIGNAL(MsgSignal(bool)),this,SLOT(CarDownProcess(bool)));
    //获取时间
    my_network->webInforTime = new QNetworkAccessManager(this);
    QObject::connect(my_network->webInforTime, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(TimefinishedSlot(QNetworkReply*)));
    //固定车更新接口
    my_network->webInforCar  = new QNetworkAccessManager(this);
    QObject::connect(my_network->webInforCar, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(CarfinishedSlot4(QNetworkReply*)));
    //通行记录上传接口
    my_network->webInforInOutup = new QNetworkAccessManager(this);
    //通行记录下载接口
    my_network->webInforInOutdown = new QNetworkAccessManager(this);
    QObject::connect(my_network->webInforInOutdown, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(InOutfinishedSlot6(QNetworkReply*)));
    //车位信息下载
    my_network->webInforcarstall = new QNetworkAccessManager(this);
    QObject::connect(my_network->webInforcarstall, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(carstallfinishedSlot(QNetworkReply*)));

    my_network->webInforcarbind = new QNetworkAccessManager(this);
    //固定车车位信息绑定下载接口
    QObject::connect(my_network->webInforcarbind, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(carbindfinishedSlot(QNetworkReply*)));
    qDebug()<<"initWeb";
    //用户下载
    down_user =new UserDown(this->myDb);
    down_user->start();
}


void MainWindow::initCamera()
{
    //显示屏及语音提示
    this->cameraIn = new camera();
    this->cameraOut = new camera();

    cameraJsonIn=new CameraJson();
    QString CameraInIp,CameraOutIp;
    CameraInIp=CameraIp("IN");
    qDebug()<<"IN======"<<sysInfo->cameraInIp<<CameraInIp;
    ui->stackedWidget_cameraIn->setCurrentIndex(0);
    ui->stackedWidget_cameraOut->setCurrentIndex(0);

    timer_update=new QTimer(this);//显示屏定时发送时间
    connect(timer_update,SIGNAL(timeout()),this,SLOT(dispUpdata()));//界面时间

    timer_update2=new QTimer(this);//显示屏定时发送时间
    connect(timer_update2,SIGNAL(timeout()),this,SLOT(dispUpdata2()));//界面时间

    if(!CameraInIp.isEmpty())
    {
        //初始化车牌识别入口摄像机连接
        connect(this->cameraIn,SIGNAL(carNumberRecEnd(QString,QPixmap*)),SLOT(carNumberIn_Slot(QString,QPixmap*)));
        connect(this->cameraIn,SIGNAL(CameraLongConnect()),this,SLOT(Camera_LinkIn()));
        connect(this,SIGNAL(WuPaiCarSend()),this,SLOT(WuPaiCarRecive()));
        WuPaiCarFlag=false;
        //摄像机TCP
        this->cameraIn->socket_link(CameraInIp);
        this->cameraJsonIn->socket_link(CameraInIp);
        ui->axWidgetIn->setProperty("ipstr",CameraInIp);
    }
    CameraOutIp=CameraIp("OUT");
    qDebug()<<"OUT======"<<CameraOutIp;
    if(!CameraOutIp.isEmpty())
    {
        //初始化车牌识别出口摄像机连接
        connect(this->cameraOut,SIGNAL(carNumberRecEnd(QString,QPixmap*)),SLOT(carNumberOut_Slot(QString,QPixmap*)));
        connect(this->cameraOut,SIGNAL(CameraLongConnect()),this,SLOT(Camera_LinkOut()));
        connect(this,SIGNAL(CarOutSend(QString)),this,SLOT(CarOutRecive(QString)));
        CarOutFlag=false;
        //摄像机TCP
        this->cameraOut->socket_link(CameraOutIp);
        ui->axWidgetOut->setProperty("ipstr",CameraOutIp);
    }
}

QString  MainWindow::CameraIp(QString flag)
{
    QString cameraTcpIp;
    if(flag == "IN")
    {
        if(sysInfo->cameraInIp.isEmpty())
        {
            if(sysInfo->cameraInIpBei.isEmpty())
            {
                cameraTcpIp.clear();
            }else{
                cameraTcpIp= sysInfo->cameraInIpBei;
            }
        }else{
            cameraTcpIp = sysInfo->cameraInIp;
        }
    }else{
        if(sysInfo->cameraOutIp.isEmpty())
        {
            if(sysInfo->cameraOutIpBei.isEmpty())
            {
                cameraTcpIp.clear();
            }else{
                cameraTcpIp =sysInfo->cameraOutIpBei;
            }
        }else{
            cameraTcpIp= sysInfo->cameraOutIp;
        }
    }
    return cameraTcpIp;
}

void MainWindow::Camera_LinkIn()
{
    ui->stackedWidget_cameraIn->setCurrentIndex(1);
    timer_update->start(10000);
}

void MainWindow::Camera_LinkOut()
{
    ui->stackedWidget_cameraOut->setCurrentIndex(1);
    timer_update2->start(10000);
}


void MainWindow::carNumberIn_Slot(QString carNum, QPixmap *pic)  ///入口抓拍
{
    bool mes,nes;
    this->inPixmap = *pic;
    if(sysInfo->savePicture==1)
    {
        pic->save(QString("in.jpg"),"JPG");
    }
    QDateTime time = QDateTime::currentDateTime();
    QString pound_no = time.toString("yyyy-MM-dd-hh-mm-ss-zzz");
    Camera_picIn=pound_no+"1.jpg";
    QString pic_date=time.toString("yyyy-MM-dd");
    ui->label_PictureIn->setPixmap(this->inPixmap);
    //carNum="晋APR356";
    if(!carNumberIn_flag)
    {
        return;
    }
    ui->pushButton_carIn->setText(carNum);
    if(WuPaiCarFlag)
    {
        if(sysInfo->savePicture==1)
        {
            filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
        }
        emit WuPaiCarSend();
        WuPaiCarFlag=false;
        return;
    }
    if(sysInfo->cameraInIp.isEmpty())
    {
        return;
    }
    displayData_t info;
    bzeroInfo(info);

    if(carNum.isEmpty())
    {
        info.audioStr = "车牌未识别请倒车重新识别  ";
        info.DispelayStr[3] = info.audioStr;
        this->cameraIn->socket_short_display(&info);
        timer_update->start(10000); ///启动还原屏幕信息函数
        return;
    }
    Car_InVehicle=carNum;
    if(sysInfo->passFlag==1)
    {
        int car_res;
        car_res=showMap(carNum,"入");
        if(car_res==1)
        {
            qDebug()<< carNum;
        }else if(car_res==0)
        {
            car_map[carNum] = Carployee("入",QDateTime::currentDateTime());
        }else if(car_res==2){
            //QByteArray sendArray;
            info.audioStr=QString("请%1秒后重新识别").arg(pass_flag_heart);
            info.DispelayStr[3] = info.audioStr;
            this->cameraIn->socket_short_display(&info);
            timer_update->start(10000); ///启动还原屏幕信息函数
            return;
        }
    }

    nes=this->myDb->updateCarOutLog(&this->myDb->sqlite_db,carNum);
    if(nes)
    {
        info.audioStr=QString("%1已有入场记录无法入场").arg(carNum);
        info.DispelayStr[3] = info.audioStr;
        this->cameraIn->socket_short_display(&info);
        timer_update->start(10000); ///启动还原屏幕信息函数
        return;
    }
    ticketCheck_t carInfo3;
    QString use_code;

    timer_update->stop();
    mes=this->myDb->car_chek(&this->myDb->sqlite_db,&carInfo3,QString::number(sysInfo->vehicleFlag),carNum);
    if(mes)//固定车
    {
        ui->pushButton_carIn->setText(carNum);
        QStringList stall_code=this->myDb->select_stall_code(&this->myDb->sqlite_db,carNum);
        if(stall_code.count()>0)//固定车绑定车位
        {
            use_code=this->myDb->check_stall_car(&this->myDb->sqlite_db,carNum,stall_code);
            qDebug()<<"use_code"<<use_code;
            if(use_code=="null")//占用车位
            {
                qDebug()<<"固定车"<<carNum<<"-车位已满-无法入场";
                info.audioStr = "固定车"+carNum+" 车位已满 无法入场";
                info.DispelayStr[3] = info.audioStr;
                makeAudio(info);
                this->cameraIn->socket_short_display(&info);

            }else{
                if(sysInfo->savePicture==1)
                {
                    filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
                }
                nes=this->myDb->writeCarInLog(&this->myDb->sqlite_db,carNum,Camera_picIn,"固定车",use_code,"已入",USER);
                if(nes){
                    qDebug()<<"固定车-绑定车位-入口通行记录更新完成"<<sysInfo->savePicture;
                }
                info.audioStr = QObject::tr("固定车").append(carNum).append("欢迎光临");
                info.DispelayStr[3] = info.audioStr;
                makeAudio(info);
                this->cameraIn->socket_short_display(&info);
                timer_in->start(300);

            }
        }
        else//固定车，没有绑定车位
        {
            if(sysInfo->savePicture==1)
            {
                filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
                //  this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carNum,pic_date);
            }
            nes=this->myDb->writeCarInLog(&this->myDb->sqlite_db,carNum,Camera_picIn,"固定车",use_code,"已入",USER);
            if(nes){
                qDebug()<<"固定车-没有绑定车位-入口通行记录更新完成"<<sysInfo->savePicture;
            }
            info.DispelayStr[1] ="固定车";
            info.DispelayStr[2] =carNum;
            info.DispelayStr[3] =QString("欢迎光临");
            makeAudio(info);
            this->cameraIn->socket_short_display(&info);
            timer_in->start(300);

        }
        info_upLink();
    }
    else{//临时车
        bool res;
        res=carInSys(Car_InVehicle);
        if(res)
        {
            timer_in->start(300);
            this->myDb->writeCarInLog(&this->myDb->sqlite_db,carNum,Camera_picIn,carInfo3.car_type,carInfo3.person_address,"已入",USER);
            if(sysInfo->savePicture==1)
            {
                filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
                //this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carNum,pic_date);
            }
        }
    }
    timer_update->start(3000);
}

void MainWindow::carNumberOut_Slot(QString carNum, QPixmap *pic)  //出口抓拍
{
    bool res;
    displayData_t info;
    info.audioStr.clear();
    for(int j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    this->outPixmap = *pic;
    if(sysInfo->savePicture==1)
    {
        pic->save(QString("out.jpg"),"JPG");
    }
    QDateTime time = QDateTime::currentDateTime();
    QString pound_no = time.toString("yyyy-MM-dd-hh-mm-ss-zzz");
    Camera_picOut=pound_no+"2.jpg";
    QString pic_date=time.toString("yyyy-MM-dd");
    ui->label_PictureOut->setPixmap(this->outPixmap);
    //carNum="晋APR356";
    if(!carNumberOut_flag)
    {
        return;
    }
    ui->pushButton_carOut->setText(carNum);
    if(sysInfo->cameraOutIp.isEmpty())
    {
        return;
    }

    if(CarOutFlag)
    {
        emit CarOutSend(CARNO);
        CarOutFlag=false;
        CARNO.clear();
        return ;
    }
    if(carNum.isEmpty())
    {

        info.audioStr ="车牌未识别请倒车重新识别  ";
        info.DispelayStr[3] = info.audioStr;
        this->cameraOut->socket_short_display(&info);

        if(sysInfo->savePicture==1)
        {
            //filelink->copyFile(DIRTEMP,CAROUT,Camera_picOut);
            filelink->copyFileToDate(pic_date,CAROUT,Camera_picOut);
            res=this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,carNum,pic_date);
        }
        timer_update2->start(10000);
        return;
    }

    Car_OutVehicle=carNum;
    if(sysInfo->passFlag==1)
    {
        int car_res;
        car_res=showMap(carNum,"出");
        if(car_res==1)
        {
            qDebug()<<carNum;
        }else if(car_res==0)
        {
            car_map[carNum] = Carployee("出",QDateTime::currentDateTime());
        }
        else if(car_res==2){
            info.audioStr=QString("请%1秒后重新识别").arg(pass_flag_heart);
            info.DispelayStr[3] = info.audioStr;
            this->cameraOut->socket_short_display(&info);
            timer_update2->start(10000); ///启动还原屏幕信息函数
            return;
        }
    }
    ui->pushButton_CarNo->setText(carNum);
    timer_update2->stop();
    CarOutRecive(carNum);
    timer_update2->start(10000);
}


void MainWindow::CarOutRecive(QString car_no)
{
    displayData_t info;
    info.audioStr.clear();
    for(int j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    ticketCheck_t carInfo1;

    bool res;
    res=this->myDb->car_chek(&this->myDb->sqlite_db,&carInfo1,QString::number(sysInfo->vehicleFlag),car_no);
    if(res)
    {
        // if(carInfo1.ticketReturn=="nomal")//固定车
        // {
        ui->pushButton_carOut->setText(car_no);
        bzeroInfo(info);
        timer_out->start(300);
        info.DispelayStr[1]="固定车";
        info.DispelayStr[2]=car_no;
        info.DispelayStr[3]="一路平安请出场 ";
        makeAudio(info);
        this->cameraOut->socket_short_display(&info);

        bool nes;
        nes=this->myDb->CarOutInfo(&this->myDb->sqlite_db,QString::number(sysInfo->vehicleFlag),car_no,&Car_OutInfor);
        if(nes){
            Car_OutInfor.user=USER;
            Car_OutInfor.car_type="固定车";
            Car_OutInfor.update_time=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
            Car_OutInfor.receivable=QString::number(0);
            Car_OutInfor.actual_money=QString::number(0);
            Car_OutInfor.discount=QString::number(0);
            res=this->myDb->writeCarOutLog(&this->myDb->sqlite_db,Camera_picOut,"0",&Car_OutInfor);
        }
        if(sysInfo->savePicture==1){
            filelink->copyFileToDate(Camera_picOut.left(10),CAROUT,Camera_picOut);
            // this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,car_no,pic_date);
        }
        //上传车辆通行记录
        info_upLink();
        //        }else{
        //            ui->pushButton_carOut->setText(carInfo1.car_type+QString(" ")+car_no);
        //            info.DispelayStr[1]="";
        //            info.DispelayStr[2]=car_no;
        //            info.DispelayStr[3]=carInfo1.ticketReturn;
        //            makeAudio(info);
        //            this->cameraOut->socket_short_display(&info);
        //        }
    }else{
        res=this->myDb->CarOutInfo(&this->myDb->sqlite_db,QString::number(sysInfo->vehicleFlag),car_no,&Car_OutInfor);
        if(res)
        {
            ui->pushButton_carOut->setText(car_no);
            double money;
            Car_OutInfor.user=USER;
            Car_OutInfor.update_time=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
            if(Car_OutInfor.dayAuto==1)
            {
                money=this->myDb->get_park_money(&this->myDb->sqlite_db,Car_OutInfor.beginTime,Car_OutInfor.endTime,"临时车");
                Car_OutInfor.receivable=QString("%1").arg(money);
                Car_OutInfor.actual_money=Car_OutInfor.receivable;
            }else{
                money=this->myDb->get_park_money(&this->myDb->sqlite_db,Car_OutInfor.beginTime,Car_OutInfor.endTime,"探亲车");
                Car_OutInfor.receivable=QString("%1").arg(money);
                Car_OutInfor.actual_money=Car_OutInfor.receivable;
            }
            ui->textBrowser_CarStatus->clear();
            ui->textBrowser_CarStatus->append(QString("车类型:%1").arg(Car_OutInfor.car_type));
            ui->textBrowser_CarStatus->append(QString("停车时长:%1").arg(Car_OutInfor.parkTime));
            //ui->textBrowser_CarStatus->append(QString("停车时长:%1小时%2分钟\t").arg(QString::number(STALL_TIME/60)).arg(QString::number(STALL_TIME%60)));
            ui->textBrowser_CarStatus->append(QString("收费金额:%1元").arg(Car_OutInfor.actual_money));
            ui->textBrowser_CarStatus->append(QString("优惠金额:%1元").arg(0));

            info.DispelayStr[1]=QString("临时车%1").arg(car_no);
            info.DispelayStr[2]=QString("停车%1").arg(Car_OutInfor.parkTime);
            info.DispelayStr[3]=QString("收费%1元").arg(Car_OutInfor.actual_money);

            info.audioStr= info.DispelayStr[3];
            this->cameraOut->socket_short_display(&info);
            if(Car_OutInfor.money==0)
            {
                if(sysInfo->HandFlag==0 )
                {
                    timer_out->start(300);
                }
                this->myDb->writeCarOutLog(&this->myDb->sqlite_db,Camera_picOut,QString::number(Car_OutInfor.money),&Car_OutInfor);
            }
        }else{
            ui->pushButton_carOut->setText(car_no);

            ui->textBrowser_CarStatus->clear();
            ui->textBrowser_CarStatus->append(QString("车类型:临时车"));
            ui->textBrowser_CarStatus->append(QString("无入场记录"));
            //ui->textBrowser_CarStatus->append(QString("停车时长:%1小时%2分钟\t").arg(QString::number(STALL_TIME/60)).arg(QString::number(STALL_TIME%60)));
            ui->textBrowser_CarStatus->append(QString("收费金额:0元"));
            ui->textBrowser_CarStatus->append(QString("优惠金额:0元"));

            bzeroInfo(info);

            info.DispelayStr[1]=" 临时车 ";
            info.DispelayStr[2]=car_no;
            info.DispelayStr[3]="无入场记录 ";
            makeAudio(info);
            this->cameraOut->socket_short_display(&info);
        }
    }
}

void MainWindow::initFile()
{
    filelink = new FileManage();
    qDebug()<<"initFile";
}

void MainWindow::bzeroInfo(displayData_t &info) //初始化语音 屏幕信息
{
    info.audioStr.clear();
    int j;
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
}
void MainWindow::makeAudio(displayData_t &info) //合成语音
{
    int i=0;
    for(i=1;i<4;i++)
    {
        if(!info.DispelayStr[i].isEmpty())
            info.audioStr.append(info.DispelayStr[i].trimmed());
    }
}

void MainWindow::TimefinishedSlot(QNetworkReply *reply)//获取时间
{
    carMessage carOutfor;
    displayData_t info;
    ///bzero(&info,sizeof(info));
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    bool res;
    res=my_network->generalWebTime(reply,&carOutfor);
    qDebug()<<"TimefinishedSlot"<<res;
    if(res)
    {
        if(!sysInfo->cameraInIp.isEmpty())
        {
            this->cameraIn->socket_short_display(&info);
        }
        if(!sysInfo->cameraOutIp.isEmpty())
        {
            this->cameraIn->socket_short_display(&info);
        }
    }
    this->down_network->start();
}

void MainWindow::CarfinishedSlot4(QNetworkReply *reply)//web下载固定车信息返回
{
    carMessage carInfor;
    my_network->generalWebCarMessage(reply,&carInfor);
}

void MainWindow::InOutfinishedSlot6(QNetworkReply *reply)//web下载通行记录返回
{
    QString time;
    time=this->myDb->select_updateTime_record(&this->myDb->sqlite_db);
    my_network->generalWebInOutdown(reply,time);
}

void MainWindow::carstallfinishedSlot(QNetworkReply *reply)
{
    my_network->generalWebcarstalldown(reply);
}


void MainWindow::carbindfinishedSlot(QNetworkReply *reply)
{
    my_network->generalWebcarbinddown(reply);
}


int MainWindow::showMap(QString car_no,QString carFlag)
{
    qDebug()<<tr("size of this carmap is :")<< car_map.count();
    if(car_map.isEmpty())
    {
        return  0;
    }else{
        if(car_map.contains(car_no))
        {
            CarParkMap::Iterator it=car_map.find(car_no);
            qDebug()<<"*******"<<  it.value().carName();
            if(it.value().carName()==carFlag)
            {
                return 1;
            }else{
                QDateTime created_time=it.value().surTime();
                QDateTime now_day=QDateTime::currentDateTime();
                int m=  created_time.secsTo(now_day);
                int n=sysInfo->heart-m;
                pass_flag_heart=n;
                return 2;
            }
        }else{
            return 0;
        }
    }
}

void MainWindow::map_carLink()
{
    if(car_map.count()==0)
    {
        return;
    }
    CarParkMap::Iterator itt;
    QDateTime mday=QDateTime::currentDateTime();
    for ( itt = car_map.begin(); itt != car_map.end(); ++itt )
    {
        QDateTime mod = itt.value().surTime();
        qDebug()<<itt.key()<<itt.value().carName()<<mod.secsTo(mday);
        if(mod.secsTo(mday) >sysInfo->heart)
        {
            car_map.remove(itt.key());
        }
    }
}

void MainWindow::Car_downLink()
{
    timer_CarDown->stop();
    this->down_network->start();
}

//下载车辆通行记录
void MainWindow::info_downLink()
{
    qDebug()<<"=====下载车辆通行记录info_downLink()Start=====";
    timer_recordDown->stop();
    QString max_updated_at;
    max_updated_at=this->myDb->select_updateTime_record(&this->myDb->sqlite_db);
    my_network->WebPost_InOutRecorddownload(max_updated_at);
    timer_recordDown->start(60000);
    qDebug()<<"=====下载车辆通行记录info_downLink()End=======";
}

//下载车辆车位绑定信息
void MainWindow::seatbind_downLink()
{
    qDebug()<<"=====下载车辆车位绑定信息seatbind_downLink()Start=====";
    timer_bind_down->stop();
    QString max_updated_at;
    max_updated_at=this->myDb->select_updateTime_carbind(&this->myDb->sqlite_db);
    my_network->WebPost_carbind_download(max_updated_at);
    timer_bind_down->start(150000);
    qDebug()<<"=====下载车辆车位绑定信息seatbind_downLink()End=======";
}

void MainWindow::car_stall_downLink()
{
    qDebug()<<"=====下载车位信息car_stall_downLink()Start=====";
    timer_stall_down->stop();
    QString max_updated_at;
    max_updated_at=this->myDb->select_updateTime_carstall(&this->myDb->sqlite_db);
    qDebug()<<"WebPost==MainWindow::car_stall_download -max_updated_at"<<max_updated_at;
    my_network->WebPost_car_stall_download(max_updated_at);
    timer_stall_down->start(300000);
    qDebug()<<"=====下载车位信息car_stall_downLink()End=======";
}
//上传车辆通行记录
void MainWindow::info_upLink()
{
    qDebug()<<"=====上传车辆通行记录info_upLink()Start=====";
    timer_recordup->stop();
    ticketCheck_t checkinfo;
    web_record_in_out record1;
    QByteArray mybaty;
    record1=this->myDb->select_inout_record(&this->myDb->sqlite_db,record1);
    if(record1.car_no ==" ")
    {
        qDebug()<<"无上传通行记录";
        timer_recordup->start(30000);
        qDebug()<<"=====上传车辆通行记录info_upLink()End=======";
        return;
    }
    checkinfo.car_no=record1.car_no;
    checkinfo.status=record1.status;
    checkinfo.inImage=record1.in_image;
    checkinfo.outImage=record1.out_image;
    bool res=this->myDb->inOutimage_selcet(&this->myDb->sqlite_db,&checkinfo);
    if(res)
    {
        mybaty= filelink->openMyDateFile(checkinfo.dirflag,checkinfo.ticketReturn);
        if(mybaty.isEmpty())
        {
            this->myDb->inOutimage_move(&this->myDb->sqlite_db,checkinfo.ticketReturn);
        }
        qDebug()<<"上传通行记录有图"<<checkinfo.car_no;
        my_network->WebPost_InOutRecordupload(record1,mybaty);
    }else{
        mybaty.clear();
        qDebug()<<"上传通行记录无图"<<checkinfo.car_no;
        my_network->WebPost_InOutRecordupload(record1,mybaty);
    }
    timer_recordup->start(30000);
    qDebug()<<"=====上传车辆通行记录info_upLink()End=======";
}

void MainWindow::CarDownProcess(bool flag)
{
    if(flag)
    {
        timer_CarDown->start(5000);
    }else{
        timer_CarDown->start(20000);
    }
}

void MainWindow::camera_in() //入口起杆
{
    timer_in->stop();
    //timer_carIn->stop();
    //this->cameraIn->socket_short_request(REQUEST_OPEN);
    this->cameraIn->socket_short_request_open(REQUEST_OPEN);
    //timer_update->start(10000);

    carNumberIn_flag=false;
    timer_quit_carNumberIn->start(CAMERA_OFF_TIMER);

    Car_InVehicle.clear();
    Camera_picIn.clear();
    qDebug()<<"***camera_in***"<<Car_InVehicle<<Car_InVehicle.length();
    //    if(sysInfo->model!=3)
    //    {
    //        QByteArray sendArray;
    //        QString send_mes;
    //        send_mes.append("001%1");
    //        send_mes.append(QString("空位: %1个$$").arg(CAR_SEAT));
    //        sendArray = gb2312->fromUnicode(send_mes);
    //        udpLed->socket_led_display(sendArray);
    //    }
}

void MainWindow::camera_out()
{
    timer_out->stop();
    //this->cameraOut->socket_short_request(REQUEST_OPEN);
    this->cameraOut->socket_short_request_open(REQUEST_OPEN);
    timer_update2->start(10000); ///做修改将出口还原时间函数加入

    carNumberOut_flag=false;
    timer_quit_carNumberOut->start(CAMERA_OFF_TIMER);
    Car_OutInfor.pass_num.clear();

    Car_OutVehicle.clear();
    ui->pushButton_carOut->setText("待通行");
    ui->textBrowser_CarStatus->setPlainText("待通行");
    //    if(sysInfo->model!=3)
    //    {
    //        QByteArray sendArray;
    //        QString send_mes;
    //        send_mes.append("!#001%1");
    //        send_mes.append(QString("空位: %1个$$").arg(CAR_SEAT));
    //        // QString send_mes=QString("空位")+CAR_SEAT+QString("个");
    //        sendArray = gb2312->fromUnicode(send_mes);
    //        udpLed->socket_led_display(sendArray);
    //    }
}

void MainWindow::quit_carNumberIn()
{
    timer_quit_carNumberIn->stop();
    carNumberIn_flag=true;
}

void MainWindow::quit_carNumberOut()
{
    timer_quit_carNumberOut->stop();
    carNumberOut_flag=true;
}

void MainWindow::closeEvent( QCloseEvent * event )
{
//    timer_update->stop();
//    timer_in->stop();
//    timer_out->stop();
//    timer_CarDown->stop();
//    delete  timer_update;
//    delete timer_in;
//    delete timer_out;
//    delete  timer_CarDown;
    event->accept();
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == ui->label_PictureIn)//入场图片
    {
        if (event->type() == QEvent::MouseButtonPress)
        {
            if(!this->inPixmap.isNull())
            {
                scroll= new scrollarea;
                scroll->set_image(&this->inPixmap);
                scroll->show();
            }
            return true;
        } else {
            return false;
        }
    }
    else if (obj == ui->label_PictureOut)//出场图片
    {
        if (event->type() == QEvent::MouseButtonPress)
        {
            if(!this->outPixmap.isNull())
            {
                scroll= new scrollarea;
                scroll->set_image(&this->outPixmap);
                scroll->show();
            }
            return true;
        } else {
            return false;
        }
    }else if(obj == ui->label_RecordInPicture){
        if (event->type() == QEvent::MouseButtonPress){
            if(!this->inRecordPixmap.isNull()){
                scroll= new scrollarea;
                scroll->set_image(&this->inRecordPixmap);
                scroll->show();
            }return true;
        }else{
            return false;
        }

    }else if(obj == ui->label_RecordOutPicture){
        if (event->type() == QEvent::MouseButtonPress){
            if(!this->outRecordPixmap.isNull()){
                scroll= new scrollarea;
                scroll->set_image(&this->outRecordPixmap);
                scroll->show();
            }return true;
        }else{
            return false;
        }
    }
    else if(obj == ui->label_ParkInPic){
        if (event->type() == QEvent::MouseButtonPress){
            if(!this->InParkPixmap.isNull()){
                scroll= new scrollarea;
                scroll->set_image(&this->InParkPixmap);
                scroll->show();
            }return true;
        }else{
            return false;
        }
    }

    else{
        return MainWindow::eventFilter(obj, event);
    }
}

void MainWindow::on_toolButton_InCar_clicked()
{
    if(!sysInfo->cameraInIp.isEmpty() && ui->stackedWidget_cameraIn->currentIndex()==1)
    {
        this->cameraIn->socket_short_request(REQUEST_TARGET);
    }
}

void MainWindow::on_toolButton_OutCar_clicked()
{
    if(!sysInfo->cameraOutIp.isEmpty() && ui->stackedWidget_cameraOut->currentIndex()==1)
    {
        this->cameraOut->socket_short_request(REQUEST_TARGET);
    }
}

void MainWindow::on_toolButton_OpenIn_clicked()//手动起杆
{
    HandCarIn(Car_InVehicle);
}

void MainWindow::HandCarIn(QString car_no)
{
    if(ui->stackedWidget_cameraIn->currentIndex()==0)
    {
        return;
    }
    displayData_t info;
    bzeroInfo(info);
    // 显示屏及语音提示
    if(car_no!="无牌")
    {
        info.DispelayStr[2]=car_no;
    }
    info.DispelayStr[3]="欢迎入场  ";
    qDebug()<<"MainWindow::HandCarIn****"<<info.DispelayStr[2]<<info.DispelayStr[3];
    for(int i=1;i<4;i++)
    {
        if(!info.DispelayStr[i].isEmpty())
        {
            info.audioStr.append(info.DispelayStr[i]);
        }
    }
    this->cameraIn->socket_short_display(&info);
    if(!car_no.isEmpty())
    {
        //nes=this->myDb->updateCarOutLog(&this->myDb->sqlite_db,Car_InVehicle);
        this->myDb->writeCarInLog(&this->myDb->sqlite_db,car_no,Camera_picIn,"临时车","","已入",USER);
    }
    timer_in->start(250);
    if(sysInfo->savePicture==1)
    {
        QString Pic_date=QDate::currentDate().toString("yyyy-MM-dd");
        filelink->copyFileToDate(Pic_date,CARIN,Camera_picIn);
    }
}

void MainWindow::on_toolButton_FreeOut_clicked()//免费通行
{
    displayData_t info;
    bzeroInfo(info);

    info.DispelayStr[2]=Car_OutVehicle;
    info.DispelayStr[3]="免费通行";
    for(int i=1;i<4;i++)
    {
        info.audioStr.append(info.DispelayStr[i]);
    }
    this->cameraOut->socket_short_display(&info);
    if(!Car_OutInfor.pass_num.isEmpty())
    {
        bool res;
        Car_OutInfor.actual_money=QString::number(0);
        Car_OutInfor.discount=QString::number(0);
        qDebug()<<"out"<<Car_OutInfor.pass_num;
        res=this->myDb->writeCarOutLog(&this->myDb->sqlite_db,Camera_picOut,QString::number(Car_OutInfor.money),&Car_OutInfor);
    }
    timer_out->start(250);
    if(sysInfo->savePicture==1)
    {
        filelink->copyFileToDate(Camera_picOut.left(10),CAROUT,Camera_picOut);
    }
}


void MainWindow::ExcleToWidgetCarManage()
{
    QString filename = QFileDialog::getOpenFileName(this, tr("Excel file"), qApp->applicationDirPath (),

                                                    tr("Files (*.xls *.xlsx)"));
    if(filename.isEmpty())
    {
        return;
    }
    excel.Open(filename);
    excel.ReadDataToTable(ui->tableWidget_CarManage); //导入到widget中
    excel.Close();
}

void MainWindow::WidgetCarManageToExcle()
{
    QString filename = QFileDialog::getSaveFileName(this, tr("Excel file"), tr("车辆管理表"),

                                                    tr("Files (*.xls *.xlsx)"));
    if (filename.isEmpty())
    {
        return;
    }
    excel.Open(filename);
    excel.SaveDataFrTable(ui->tableWidget_CarManage); //导出报表
    excel.Close();
}

void MainWindow::on_toolButton_SysLinIn_clicked()
{
    if(tool_SysLinIn)
    {
        ui->toolButton_SysLinIn->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysLinIn->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysLinIn=!tool_SysLinIn;
}

void MainWindow::on_toolButton_SysPassTimeCar_clicked()
{
    if(tool_SysPassTimeCar)
    {
        ui->toolButton_SysPassTimeCar->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysPassTimeCar->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysPassTimeCar=!tool_SysPassTimeCar;
}

void MainWindow::on_toolButton_SysFeeCarOut_clicked()
{
    if(tool_SysFeeCarOut)
    {
        ui->toolButton_SysFeeCarOut->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysFeeCarOut->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysFeeCarOut=!tool_SysFeeCarOut;
}

void MainWindow::on_toolButton_SysPrint_clicked()
{
    if(tool_SysPrint)
    {
        ui->toolButton_SysPrint->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysPrint->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysPrint=!tool_SysPrint;
}

void MainWindow::on_toolButton_SysCarHan_clicked()
{
    if(tool_SysCarHan)
    {
        ui->toolButton_SysCarHan->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysCarHan->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysCarHan=!tool_SysCarHan;
}

void MainWindow::on_toolButton_SysFee_clicked()
{
    if(tool_SysFee)
    {
        ui->toolButton_SysFee->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysFee->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysFee=!tool_SysFee;
}

void MainWindow::on_toolButton_SysBack_clicked()
{
    if(tool_SysBack)
    {
        ui->toolButton_SysBack->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysBack->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysBack=!tool_SysBack;
}

void MainWindow::on_toolButton_SysAllCar_clicked()
{
    if(tool_SysAllCar)
    {
        ui->toolButton_SysAllCar->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysAllCar->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysAllCar=!tool_SysAllCar;
}

void MainWindow::on_toolButton_SysUser_clicked()
{
    if(tool_SysUser)
    {
        ui->toolButton_SysUser->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysUser->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysUser=!tool_SysUser;
}

void MainWindow::on_toolButton_SysSeat_clicked()
{
    if(tool_SysSeat)
    {
        ui->toolButton_SysSeat->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysSeat->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysSeat=!tool_SysSeat;
}

void MainWindow::on_toolButton_SysTopFee_clicked()
{
    if(tool_SysTopFee)
    {
        ui->toolButton_SysTopFee->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
    }else{
        ui->toolButton_SysTopFee->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
    }
    tool_SysTopFee=!tool_SysTopFee;
}

void MainWindow::on_toolButton_FeeFreeBool_clicked()
{
    if(tool_FeeFreeBool)
    {
        ui->toolButton_FeeFreeBool->setStyleSheet(tr("border-image: url(:/images/off.png);"));
    }else{
        ui->toolButton_FeeFreeBool->setStyleSheet(tr("border-image: url(:/images/on.png);"));
    }
    tool_FeeFreeBool=!tool_FeeFreeBool;
}

void MainWindow::on_toolButton_Fee24Bool_clicked()
{
    if(tool_Fee24Bool)
    {
        ui->toolButton_Fee24Bool->setStyleSheet(tr("border-image: url(:/images/off.png);"));
    }else{
        ui->toolButton_Fee24Bool->setStyleSheet(tr("border-image: url(:/images/on.png);"));
    }
    tool_Fee24Bool=!tool_Fee24Bool;
}


void MainWindow::Record_InOutPicShow(QString inPic, QString outPic)
{
    //QString  Lpath=res+"/"+pic_name;
    //CarInPicName=Lpath;
    QFile my_infile(inPic);
    QFile my_outfile(outPic);
    if(my_infile.exists())
    {
        QPixmap aa(inPic);
        //aa.loadFromData(mybaty,0,Qt::AutoColor);
        ui->label_RecordInPicture->setPixmap(aa);
    }
    if(my_outfile.exists())
    {
        QPixmap aa(outPic);
        //aa.loadFromData(mybaty,0,Qt::AutoColor);
        ui->label_RecordOutPicture->setPixmap(aa);
    }
    ui->label_RecordInPicture->setPixmap(QPixmap("url(:/images/u2.png)"));
    ui->label_RecordOutPicture->setPixmap(QPixmap("url(:/images/u2.png)"));
}
void MainWindow::on_tableWidget_Record_doubleClicked(const QModelIndex &index)
{
    Record_InOutPicShow("","");
}

void MainWindow::on_tableWidget_SrearchFeeRecord_doubleClicked(const QModelIndex &index)
{
    Record_InOutPicShow("","");
}

void MainWindow::on_pushButton_CarManageNew_clicked()
{
    ui->stackedWidget_Sys->setCurrentIndex(5);
    ui->dateTimeEdit_NewCarBegin->setDateTime(QDateTime::currentDateTime());
    ui->dateTimeEdit_NewCarEnd->setDateTime(QDateTime::currentDateTime().addDays(30));
    on_comboBox_NewCarType_activated("固定车");
}

void MainWindow::on_pushButton_NewCarQuit_clicked()
{
    ui->stackedWidget_Sys->setCurrentIndex(0);
}

void MainWindow::on_pushButton_UserNew_clicked()
{
    userDilog= new User(this->myDb,-1,"","");
    userDilog->exec();
    tableWidget_User_Show();
}

void MainWindow::sysTemReset()
{
    ui->lineEdit_SysServerIP->setText(sysInfo->serverIp);
    ui->lineEdit_SysServerIPBei->setText(sysInfo->serverIpBei);
    ui->lineEdit_SysCameraIn->setText(sysInfo->cameraInIp);
    ui->lineEdit_SysCameraInBei->setText(sysInfo->cameraInIpBei);
    ui->lineEdit_SysCameraOut->setText(sysInfo->cameraOutIp);
    ui->lineEdit_SysCameraOutBei->setText(sysInfo->cameraOutIpBei);
    ui->lineEdit_SysLed->setText(sysInfo->ledIp1);
    ui->lineEdit_SysTime->setText(QString::number(sysInfo->heart));
    ui->lineEdit_SysCompany->setText(sysInfo->galleryName);
    ui->lineEdit_SysCarNum->setText(QString::number(sysInfo->car_stall));
    ui->lineEdit_SysDay->setText("30");
    ui->lineEdit_SysId->setText(sysInfo->mac);
    if(sysInfo->tempCarIn==0)
    {
        ui->toolButton_SysLinIn->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysLinIn=false;
    }else if(sysInfo->tempCarIn==1)
    {
        ui->toolButton_SysLinIn->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysLinIn=true;
    }
    if(sysInfo->clearCar==0)
    {
        ui->toolButton_SysPassTimeCar->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysPassTimeCar=false;
    }else if(sysInfo->clearCar==1)
    {
        ui->toolButton_SysPassTimeCar->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysPassTimeCar=true;
    }
    if(sysInfo->HandFlag==0)
    {
        ui->toolButton_SysFeeCarOut->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysFeeCarOut=false;
    }else if(sysInfo->HandFlag==1)
    {
        ui->toolButton_SysFeeCarOut->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysFeeCarOut=true;
    }
    if(sysInfo->printFlag==0)
    {
        ui->toolButton_SysPrint->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysPrint=false;
    }else if(sysInfo->printFlag==1)
    {
        ui->toolButton_SysPrint->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysPrint=true;
    }
    if(sysInfo->vehicleFlag==0)
    {
        ui->toolButton_SysCarHan->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysCarHan=false;
    }else if(sysInfo->vehicleFlag==1)
    {
        ui->toolButton_SysCarHan->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysCarHan=true;
    }
    if(sysInfo->model==0)
    {
        ui->toolButton_SysFee->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysFee=false;
    }else if(sysInfo->model==1)
    {
        ui->toolButton_SysFee->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysFee=true;
    }
    if(sysInfo->first_down==0)
    {
        ui->toolButton_SysBack->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysBack=false;
    }else   if(sysInfo->first_down==1)
    {
        ui->toolButton_SysBack->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysBack=true;
    }
    if(sysInfo->park_camera==0)
    {
        ui->toolButton_SysAllCar->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysAllCar=false;
    }else  if(sysInfo->park_camera==1)
    {
        ui->toolButton_SysAllCar->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysAllCar=true;
    }
    if(sysInfo->userFlag==0)
    {
        ui->toolButton_SysUser->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysUser=false;
    }else  if(sysInfo->userFlag==1)
    {
        ui->toolButton_SysUser->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysUser=true;
    }
    if(sysInfo->park_type==0)
    {
        ui->toolButton_SysSeat->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysSeat=false;
    }else if(sysInfo->park_type==1)
    {
        ui->toolButton_SysSeat->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysSeat=true;
    }
    if(sysInfo->FeeTopFlag==0)
    {
        ui->toolButton_SysTopFee->setStyleSheet(tr("border-image: url(:/images/guan.png);"));
        tool_SysTopFee=false;
    }else if(sysInfo->FeeTopFlag==1)
    {
        ui->toolButton_SysTopFee->setStyleSheet(tr("border-image: url(:/images/kai.png);"));
        tool_SysTopFee=true;
    }
}



void MainWindow::on_pushButton_SysOk_clicked()
{
    //    if(ui->lineEdit_SysCameraIn->text().isEmpty())
    //    {
    //        QMessageBox::information(NULL, QString("提示"), QString("入口摄像机IP不能为空"));
    //        return;
    //    }
    //    if(ui->lineEdit_SysCameraOut->text().isEmpty())
    //    {
    //        QMessageBox::information(NULL, QString("提示"), QString("出口摄像机IP不能为空"));
    //        return;
    //    }
    if(ui->lineEdit_SysTime->text().isEmpty())
    {
        QMessageBox::information(NULL, QString("提示"), QString("相同车牌过滤时间不能为空"));
        return;
    }
    sysInfo->serverIp=ui->lineEdit_SysServerIP->text();
    sysInfo->serverIpBei=ui->lineEdit_SysServerIPBei->text();
    sysInfo->cameraInIp=ui->lineEdit_SysCameraIn->text();
    sysInfo->cameraInIpBei=ui->lineEdit_SysCameraInBei->text();
    sysInfo->cameraOutIp=ui->lineEdit_SysCameraOut->text();
    sysInfo->cameraOutIpBei=ui->lineEdit_SysCameraOutBei->text();
    sysInfo->ledIp1=ui->lineEdit_SysLed->text();
    sysInfo->heart=ui->lineEdit_SysTime->text().toInt();
    sysInfo->galleryName=ui->lineEdit_SysCompany->text();
    sysInfo->car_stall=ui->lineEdit_SysCarNum->text().toInt();
    ui->lineEdit_SysDay->setText("30");

    if(tool_SysLinIn)
    {
        sysInfo->tempCarIn=1;
    }else
    {
        sysInfo->tempCarIn=0;
    }

    if(tool_SysPassTimeCar)
    {
        sysInfo->clearCar=1;
    }else
    {
        sysInfo->clearCar=0;
    }

    if(tool_SysFeeCarOut)
    {
        sysInfo->HandFlag=1;
    }else
    {
        sysInfo->HandFlag=0;
    }

    if(tool_SysPrint)
    {
        sysInfo->printFlag=1;
    }else
    {
        sysInfo->printFlag=0;
    }

    if(tool_SysCarHan)
    {
        sysInfo->vehicleFlag=1;
    }else
    {
        sysInfo->vehicleFlag=0;
    }

    if(tool_SysFee)
    {
        sysInfo->model=1;
    }else
    {
        sysInfo->model=0;
    }

    if(tool_SysBack)
    {
        sysInfo->first_down=1;
    }else
    {
        sysInfo->first_down=0;
    }

    if(tool_SysAllCar)
    {
        sysInfo->park_camera=1;
    }else
    {
        sysInfo->park_camera=0;
    }

    if(tool_SysUser)
    {
        sysInfo->userFlag=1;
    }else
    {
        sysInfo->userFlag=0;
    }

    if( tool_SysSeat)
    {
        sysInfo->park_type=1;
    }else
    {
        sysInfo->park_type=0;
    }

    if(tool_SysTopFee)
    {
        sysInfo->FeeTopFlag=1;
    }else
    {
        sysInfo->FeeTopFlag=0;
    }
    switch(QMessageBox::warning(this,QObject::trUtf8("提示"),QObject::trUtf8("是否修改收费规则?"),QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Cancel))
    {
    case QMessageBox::Ok:break;
    case QMessageBox::Cancel:
        return;
    }
    sysInfo->SettingSave();
    QMessageBox::information(NULL, QString("提示"), QString("系统设置修改完成"));
}



//void MainWindow::tableWidget_CarManage_Show()
//{
//    ui->tableWidget_CarManage->clear();
//    int ret,car_num;
//    QSqlQuery query(this->myDb->sqlite_db),select_car(this->myDb->sqlite_db);
//    query.clear();
//    query.prepare(QObject::tr("select count(*) from record_stall_vehicle where status='%1'").arg(QString("正常")));
//    query.exec();
//    ret = query.next();
//    if(ret==1)
//    {
//    car_num=query.value(0).toInt();
//    }
//    ui->tableWidget_CarManage->setRowCount(car_num);
//    ui->tableWidget_CarManage->setColumnCount(7);
//    QStringList headers;
//    headers<<QString::fromUtf8("车牌号")<<QString::fromUtf8("类型")<<QString::fromUtf8("车位")<<QString::fromUtf8("联系人")<<QString::fromUtf8("电话")<<QString::fromUtf8("开始时间")<<QString::fromUtf8("结束时间");
//    ui->tableWidget_CarManage->setHorizontalHeaderLabels(headers);
//    ui->tableWidget_CarManage->horizontalHeader()->setStretchLastSection(true); //这个是关键

//    ui->tableWidget_CarManage->setColumnWidth(0,120);
//    ui->tableWidget_CarManage->setColumnWidth(1,80);
//    ui->tableWidget_CarManage->setColumnWidth(2,100);
//    ui->tableWidget_CarManage->setColumnWidth(3,120);
//    ui->tableWidget_CarManage->setColumnWidth(4,120);
//    ui->tableWidget_CarManage->setColumnWidth(5,140);
//    ui->tableWidget_CarManage->setColumnWidth(6,140);
//    select_car.exec(tr("select car_no,car_type,person_name,person_tel,start_date,stop_date from record_stall_vehicle where status='%1'  order by id asc").arg("正常"));
//    for(int i=0;select_car.next();i++){
//       QString car_no=select_car.value(0).toString();
//       QString car_seat=this->myDb->FindSeatData(&this->myDb->sqlite_db,car_no);
//       QString carType=select_car.value(1).toString();
//       QString person_name=select_car.value(2).toString();
//       QString person_tell=select_car.value(3).toString();
//       QString start=select_car.value(4).toString();
//       QString end=select_car.value(5).toString();
//       QTableWidgetItem *t_test  = new QTableWidgetItem(car_no);
//       t_test->setTextAlignment(Qt::AlignCenter);
//       QTableWidgetItem *t_test2  = new QTableWidgetItem(carType);
//       t_test2->setTextAlignment(Qt::AlignCenter);
//       QTableWidgetItem *t_test3  = new QTableWidgetItem(car_seat);
//       t_test3->setTextAlignment(Qt::AlignCenter);
//       QTableWidgetItem *t_test4  = new QTableWidgetItem(person_name);
//       t_test4->setTextAlignment(Qt::AlignCenter);
//       QTableWidgetItem *t_test5  = new QTableWidgetItem(person_tell);
//       t_test5->setTextAlignment(Qt::AlignCenter);
//       QTableWidgetItem *t_test6  = new QTableWidgetItem(start);
//       t_test6->setTextAlignment(Qt::AlignCenter);
//       QTableWidgetItem *t_test7  = new QTableWidgetItem(end);
//       t_test7->setTextAlignment(Qt::AlignCenter);

//    ui->tableWidget_CarManage->setItem(i,0,t_test);
//    ui->tableWidget_CarManage->setItem(i,1,t_test2);
//    ui->tableWidget_CarManage->setItem(i,2,t_test3);
//    ui->tableWidget_CarManage->setItem(i,3,t_test4);
//    ui->tableWidget_CarManage->setItem(i,4,t_test5);
//    ui->tableWidget_CarManage->setItem(i,5,t_test6);
//    ui->tableWidget_CarManage->setItem(i,6,t_test7);
//    }
//}

void MainWindow::tableWidget_Seat_Show()
{
    ui->tableWidget_Seat->clear();
    int ret,car_num;
    QSqlQuery query(this->myDb->sqlite_db),select_car(this->myDb->sqlite_db);
    query.clear();
    query.prepare(QObject::tr("select count(*) from vehicle_seat"));
    query.exec();
    ret = query.next();
    if(ret==1)
    {
        car_num=query.value(0).toInt();
    }
    ui->tableWidget_Seat->setRowCount(car_num);
    ui->tableWidget_Seat->setColumnCount(2);
    QStringList headers;
    headers<<QString::fromUtf8("序号")<<QString::fromUtf8("车库编号");
    ui->tableWidget_Seat->setHorizontalHeaderLabels(headers);
    ui->tableWidget_Seat->horizontalHeader()->setStretchLastSection(true); //这个是关键

    ui->tableWidget_Seat->setColumnWidth(0,0);
    ui->tableWidget_Seat->setColumnWidth(1,180);
    select_car.exec(tr("select id,print_code from vehicle_seat order by id asc"));
    for(int i=0;select_car.next();i++){
        QString id=select_car.value(0).toString();
        QString name=select_car.value(1).toString();

        QTableWidgetItem *t_test  = new QTableWidgetItem(id);
        t_test->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test2  = new QTableWidgetItem(name);
        t_test2->setTextAlignment(Qt::AlignCenter);

        ui->tableWidget_Seat->setItem(i,0,t_test);
        ui->tableWidget_Seat->setItem(i,1,t_test2);
    }
}

void MainWindow::tableWidget_Fee_Show()
{
    ui->tableWidget_Fee->clear();
    int ret,car_num;
    QSqlQuery query(this->myDb->sqlite_db),select_car(this->myDb->sqlite_db);
    query.clear();
    query.prepare(QObject::tr("select count(*) from money where car_type_name='%1'").arg(QString("临时车")));
    query.exec();
    ret = query.next();
    if(ret==1)
    {
        car_num=query.value(0).toInt();
    }
    ui->tableWidget_Fee->setRowCount(car_num);
    ui->tableWidget_Fee->setColumnCount(5);
    QStringList headers;
    headers<<QString::fromUtf8("序号")<<QString::fromUtf8("收费类型")<<QString::fromUtf8("最小时长")<<QString::fromUtf8("最大时长")<<QString::fromUtf8("收费金额");
    ui->tableWidget_Fee->setHorizontalHeaderLabels(headers);
    ui->tableWidget_Fee->horizontalHeader()->setStretchLastSection(true); //这个是关键

    ui->tableWidget_Fee->setColumnWidth(0,0);
    ui->tableWidget_Fee->setColumnWidth(1,120);
    ui->tableWidget_Fee->setColumnWidth(2,120);
    ui->tableWidget_Fee->setColumnWidth(3,120);
    ui->tableWidget_Fee->setColumnWidth(4,120);
    select_car.exec(tr("select id,car_type_name,parked_min_time,parked_max_time,money from money where car_type_name='%1'  order by id asc").arg("临时车"));
    for(int i=0;select_car.next();i++){
        QString id=select_car.value(0).toString();
        QString carN=select_car.value(1).toString();
        QString min=select_car.value(2).toString();
        QString max=select_car.value(3).toString();
        QString fee=select_car.value(4).toString().append("元");
        QTableWidgetItem *t_test  = new QTableWidgetItem(id);
        t_test->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test2  = new QTableWidgetItem(carN);
        t_test2->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test3  = new QTableWidgetItem(getFeeTime(min));
        t_test3->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test4  = new QTableWidgetItem(getFeeTime(max));
        t_test4->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test5  = new QTableWidgetItem(fee);
        t_test5->setTextAlignment(Qt::AlignCenter);

        ui->tableWidget_Fee->setItem(i,0,t_test);
        ui->tableWidget_Fee->setItem(i,1,t_test2);
        ui->tableWidget_Fee->setItem(i,2,t_test3);
        ui->tableWidget_Fee->setItem(i,3,t_test4);
        ui->tableWidget_Fee->setItem(i,4,t_test5);
    }
    feeInfo.ID.clear();
}

void MainWindow::tableWidget_User_Show()
{
    ui->tableWidget_User->clear();
    int ret,car_num;
    QSqlQuery query(this->myDb->sqlite_db),select_car(this->myDb->sqlite_db);
    query.clear();
    query.prepare(QObject::tr("select count(*) from user "));
    query.exec();
    ret = query.next();
    if(ret==1)
    {
        car_num=query.value(0).toInt();
    }
    ui->tableWidget_User->setRowCount(car_num);
    ui->tableWidget_User->setColumnCount(3);
    QStringList headers;
    QString type_name;
    headers<<QString::fromUtf8("序号")<<QString::fromUtf8("用户名")<<QString::fromUtf8("用户类型");
    ui->tableWidget_User->setHorizontalHeaderLabels(headers);
    ui->tableWidget_User->horizontalHeader()->setStretchLastSection(true); //这个是关键

    ui->tableWidget_User->setColumnWidth(0,0);
    ui->tableWidget_User->setColumnWidth(1,180);
    ui->tableWidget_User->setColumnWidth(2,120);
    select_car.exec(tr("select id,userName,type from user order by id asc"));
    for(int i=0;select_car.next();i++){
        QString id=select_car.value(0).toString();
        QString name=select_car.value(1).toString();
        QString type=select_car.value(2).toString();
        if(type=="system")
        {
            type_name ="管理员";
        }else{
            type_name ="操作员";
        }

        QTableWidgetItem *t_test  = new QTableWidgetItem(id);
        t_test->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test2  = new QTableWidgetItem(name);
        t_test2->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test3  = new QTableWidgetItem(type_name);
        t_test3->setTextAlignment(Qt::AlignCenter);

        ui->tableWidget_User->setItem(i,0,t_test);
        ui->tableWidget_User->setItem(i,1,t_test2);
        ui->tableWidget_User->setItem(i,2,t_test3);
    }
}

QString MainWindow::getFeeTime(QString fee)
{
    QString str;
    if(fee.endsWith("1"))
    {
        float min=(fee.toFloat()-1)/60;
        str=QString("%1小时").arg(min);
    }else{
        float max=(fee.toFloat())/60;
        str=QString("%1小时").arg(max);
    }
    return str;
}

void MainWindow::on_tableWidget_Fee_clicked(const QModelIndex &index)
{
    feeInfo.ID=index.sibling(index.row(),0).data().toString();
    feeInfo.ParkType=index.sibling(index.row(),1).data().toString();
    QString min_T=index.sibling(index.row(),2).data().toString();
    QString max_T=index.sibling(index.row(),3).data().toString();
    QString fee=index.sibling(index.row(),4).data().toString().remove("元");
    ui->label_FeeItem->setText(QString("%1-%2").arg(min_T).arg(max_T));
    ui->lineEdit_FeeItem->setText(fee);
}

void MainWindow::on_pushButton_FeeItemOk_clicked()
{
    if(feeInfo.ID.isEmpty()) //不可以入场
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("请选择条目"));
        return;
    }
    if(ui->lineEdit_FeeItem->text().isEmpty())
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("金额不能为空"));
        return;
    }
    bool res;
    res=this->myDb->updateFeeData(&this->myDb->sqlite_db,feeInfo.ID,feeInfo.ParkType,ui->lineEdit_FeeItem->text());
    if(res)
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("%1修改成功").arg(ui->label_FeeItem->text()));
        tableWidget_Fee_Show();
    }else{
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("%1修改成功").arg(ui->label_FeeItem->text()));
    }
}

void MainWindow::on_pushButton_FeeOk_clicked()
{
    if(ui->lineEdit_FeeHalf->text().isEmpty())
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("半小时收费金额为空"));
        return;
    }
    if(ui->lineEdit_FeeOne->text().isEmpty())
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("一小时收费金额为空"));
        return;
    }
    if(ui->lineEdit_FeeTall->text().isEmpty())
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("最高收费金额为空"));
        return;
    }
    bool res;
    res=this->myDb->setFeeData(&this->myDb->sqlite_db,"临时车",ui->lineEdit_FeeHalf->text().toFloat(),ui->lineEdit_FeeOne->text().toFloat());
    if(res)
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("收费规则修改成功"));
        tableWidget_Fee_Show();
    }else{
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("收费规则修改失败"));
    }
}

void MainWindow::on_tableWidget_User_doubleClicked(const QModelIndex &index)
{
    QString name,type;
    int flag;
    flag=index.sibling(index.row(),0).data().toInt();
    name=index.sibling(index.row(),1).data().toString();
    type=index.sibling(index.row(),2).data().toString();;
    userDilog= new User(this->myDb,flag,name,type);
    userDilog->exec();
    tableWidget_User_Show();
}

void MainWindow::runTimerOut()
{
    this->Timer_bg->stop();
    int sec = this->ClassTime.secsTo(QDateTime::currentDateTime());
    int day = sec/24/3600;
    int hour = sec%24/3600;
    int minute = sec%3600/60;

    shiftInfo.User=USER;
    shiftInfo.ParkTime=QString("%1天%2小时%3分").arg(day).arg(hour).arg(minute);
    shiftInfo.CarNum="0";
    shiftInfo.Money="0";
    //ui->label_time->setText(QString("%1天%2小时%3分").arg(day).arg(hour).arg(minute).arg(second));
    init_Shift(&shiftInfo);
    //filelink->removeFolderContent(QDir::currentPath());
    //this->Timer_bg->start(30000);
}

void MainWindow::on_pushButton_NewCarOk_clicked()
{
    if(ui->lineEdit_NewCarNo->text().isEmpty())
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("车号为空"));
        return;
    }
    if(ui->lineEdit_NewCarPerson->text().isEmpty())
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("联系人为空"));
        return;
    }

    bool res;
    ticketCheck_t carInfo;

    res=this->myDb->car_chek(&this->myDb->sqlite_db,&carInfo,"1",ui->lineEdit_NewCarNo->text());
    if(res)
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("车号已存在"));
        return;
    }

    carInfo.car_no=ui->lineEdit_NewCarNo->text();
    carInfo.update_time=QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
    carInfo.beginTime=ui->dateTimeEdit_NewCarBegin->dateTime().toString("yyyy-MM-dd hh:mm:ss");
    carInfo.endTime=ui->dateTimeEdit_NewCarEnd->dateTime().toString("yyyy-MM-dd hh:mm:ss");
    carInfo.fee_type=ui->comboBox_NewCarType->currentText();
    carInfo.car_type=ui->comboBox_NewGuCarType->currentText();
    carInfo.person_name=ui->lineEdit_NewCarPerson->text();
    carInfo.person_tel=ui->lineEdit_NewCarPhone->text();
    carInfo.person_address=ui->lineEdit_NewCarAdress->text();
    res=this->myDb->writeSqliteCar(&this->myDb->sqlite_db,&carInfo);
    if(res)
    {
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("车辆添加成功"));
        SysCarSlot();
    }else{
        QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("车辆添加失败"));
        return;
    }
}

void MainWindow::on_comboBox_NewCarType_activated(const QString &arg1)
{
    ui->comboBox_NewGuCarType->clear();
    if(arg1=="固定车")
    {
        ui->comboBox_NewGuCarType->addItem("月租车");
        ui->comboBox_NewGuCarType->addItem("年租车");
    }else{
        ui->comboBox_NewGuCarType->addItem("特殊车");
    }
}

void MainWindow::on_comboBox_NewGuCarType_activated(const QString &arg1)
{
    if(arg1=="月租车")
    {
        ui->dateTimeEdit_NewCarBegin->setDateTime(QDateTime::currentDateTime());
        ui->dateTimeEdit_NewCarEnd->setDateTime(QDateTime::currentDateTime().addDays(30));

    }else{
        ui->dateTimeEdit_NewCarBegin->setDateTime(QDateTime::currentDateTime());
        ui->dateTimeEdit_NewCarEnd->setDateTime(QDateTime::currentDateTime().addDays(365));
    }
}

void MainWindow::on_pushButton_CarManageClear_clicked()
{
    switch(QMessageBox::warning(this,QObject::trUtf8("提示"),QObject::trUtf8("是清空车辆信息?"),QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Cancel))
    {
    case QMessageBox::Ok:break;
    case QMessageBox::Cancel:
        return;
    }
    this->myDb->DeleteStall_vehicle(&this->myDb->sqlite_db);
    SysCarSlot();
}

void MainWindow::on_lineEdit_CarManageNo_textChanged(const QString &arg1)
{
    QString car_name=QString("%")+arg1+QString("%");
    QString car_type=ui->comboBox_CarManageType->currentText();
    if(arg1.isEmpty())
    {
        car_vehicle(arg1,car_type);
    }else{
        car_vehicle(car_name,car_type);
    }
}

void MainWindow::car_vehicle(QString car_no,QString car_type)
{
    QString count_res,item_res;
    ui->tableWidget_CarManage->clear();
    int ret,car_num;
    QSqlQuery query(this->myDb->sqlite_db);
    QSqlQuery select_car(this->myDb->sqlite_db);

    if(car_no.isEmpty())
    {
        if(car_type=="所有车")
        {
            count_res=QObject::tr("select count(*) from record_stall_vehicle where status='%1'").arg(QString("正常"));
            item_res=QObject::tr("select car_no,car_type,person_name,person_tel,start_date,stop_date from record_stall_vehicle where status='%1'  order by id asc").arg("正常");
        }else{
            count_res=QObject::tr("select count(*) from record_stall_vehicle where fee_type='%1' and status='%2'").arg(car_type).arg(QString("正常"));
            item_res=QObject::tr("select car_no,car_type,person_name,person_tel,start_date,stop_date from record_stall_vehicle where fee_type='%1' and status='%2'  order by updated_at asc").arg(car_type).arg(QString("正常"));
        }
    }else{
        count_res=QObject::tr("select count(*) from record_stall_vehicle where car_no like '%1' and status='%2'").arg(car_no).arg(QString("正常"));
        item_res=QObject::tr("select car_no,car_type,person_name,person_tel,start_date,stop_date from record_stall_vehicle where car_no like '%1' and status='%2' order by updated_at asc").arg(car_no).arg(QString("正常"));
    }
    query.clear();
    query.prepare(count_res);
    query.exec();
    ret = query.next();
    if(ret==1)
    {
        car_num=query.value(0).toInt();
    }else{
        car_num=0;
    }

    ui->tableWidget_CarManage->setRowCount(car_num);
    ui->tableWidget_CarManage->setColumnCount(7);
    //ui->label_widgetcount->setText(QString("合计: %1条").arg(car_num));

    QStringList headers;
    headers<<QString::fromUtf8("车牌号")<<QString::fromUtf8("类型")<<QString::fromUtf8("车位")<<QString::fromUtf8("联系人")<<QString::fromUtf8("电话")<<QString::fromUtf8("开始时间")<<QString::fromUtf8("结束时间");
    ui->tableWidget_CarManage->setHorizontalHeaderLabels(headers);
    ui->tableWidget_CarManage->horizontalHeader()->setStretchLastSection(true); //这个是关键

    ui->tableWidget_CarManage->setColumnWidth(0,120);
    ui->tableWidget_CarManage->setColumnWidth(1,80);
    ui->tableWidget_CarManage->setColumnWidth(2,100);
    ui->tableWidget_CarManage->setColumnWidth(3,120);
    ui->tableWidget_CarManage->setColumnWidth(4,120);
    ui->tableWidget_CarManage->setColumnWidth(5,140);
    ui->tableWidget_CarManage->setColumnWidth(6,140);


    select_car.prepare(item_res);
    select_car.exec();
    for(int i=0;select_car.next();i++)
    {
        QString car_no=select_car.value(0).toString();
        QString car_seat=this->myDb->FindSeatData(&this->myDb->sqlite_db,car_no);
        QString carType=select_car.value(1).toString();
        QString person_name=select_car.value(2).toString();
        QString person_tell=select_car.value(3).toString();
        QString start=select_car.value(4).toString();
        QString end=select_car.value(5).toString();
        QTableWidgetItem *t_test  = new QTableWidgetItem(car_no);
        t_test->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test2  = new QTableWidgetItem(carType);
        t_test2->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test3  = new QTableWidgetItem(car_seat);
        t_test3->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test4  = new QTableWidgetItem(person_name);
        t_test4->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test5  = new QTableWidgetItem(person_tell);
        t_test5->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test6  = new QTableWidgetItem(start);
        t_test6->setTextAlignment(Qt::AlignCenter);
        QTableWidgetItem *t_test7  = new QTableWidgetItem(end);
        t_test7->setTextAlignment(Qt::AlignCenter);

        ui->tableWidget_CarManage->setItem(i,0,t_test);
        ui->tableWidget_CarManage->setItem(i,1,t_test2);
        ui->tableWidget_CarManage->setItem(i,2,t_test3);
        ui->tableWidget_CarManage->setItem(i,3,t_test4);
        ui->tableWidget_CarManage->setItem(i,4,t_test5);
        ui->tableWidget_CarManage->setItem(i,5,t_test6);
        ui->tableWidget_CarManage->setItem(i,6,t_test7);
    }
}

/***********************张超END********************************/


void MainWindow::on_toolButton_SearchCar_clicked()
{
    //数据库查找所有车辆  插入表tableWidgetr_Car
    ui->tableWidgetr_Car->clear();
    ui->tableWidgetr_Car->setColumnCount(8);   //设置列数
    QStringList header;
    QString car_no=ui->lineEdit_CarNo->text().trimmed();
    header<<"序号"<<"车牌号"<<"类型"<<"车位"<<"联系人"<<"电话"<<"开始时间"<<"结束时间";
    ui->tableWidgetr_Car->setHorizontalHeaderLabels(header);
    int p=ui->tableWidgetr_Car->width();
    ui->tableWidgetr_Car->setColumnWidth(0,p/10);
    ui->tableWidgetr_Car->setColumnWidth(1,p/8);
    ui->tableWidgetr_Car->setColumnWidth(2,p/10);
    ui->tableWidgetr_Car->setColumnWidth(3,p/6);
    ui->tableWidgetr_Car->setColumnWidth(4,p/8);
    ui->tableWidgetr_Car->setColumnWidth(5,p/9);
    ui->tableWidgetr_Car->setColumnWidth(6,p/8);
    ui->tableWidgetr_Car->setColumnWidth(7,p/8);
    ui->tableWidgetr_Car->setAlternatingRowColors(true);
    ui->tableWidgetr_Car->verticalHeader()->setVisible(false);
    ui->tableWidgetr_Car->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidgetr_Car->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidgetr_Car->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->tableWidgetr_Car->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//去掉水平滚动条
    QList<car_stall_info> stall_info_list;
    stall_info_list=this->myDb->select_vehicle_info(&this->myDb->sqlite_db,car_no);
    ui->tableWidgetr_Car->setRowCount(stall_info_list.count());
    for(int row=0;row<stall_info_list.count();row++)
    {
        car_stall_info stall_info;
        stall_info=stall_info_list.at(row);
        ui->tableWidgetr_Car->setItem(row,0,new QTableWidgetItem(QString::number(row+1)));
        ui->tableWidgetr_Car->item(row,0)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,1,new QTableWidgetItem(stall_info.car_no));
        ui->tableWidgetr_Car->item(row,1)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,2,new QTableWidgetItem(stall_info.car_type));
        ui->tableWidgetr_Car->item(row,2)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,3,new QTableWidgetItem(stall_info.code_Id));
        ui->tableWidgetr_Car->item(row,3)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,4,new QTableWidgetItem(stall_info.person_name));
        ui->tableWidgetr_Car->item(row,4)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,5,new QTableWidgetItem(stall_info.person_tel));
        ui->tableWidgetr_Car->item(row,5)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,6,new QTableWidgetItem(stall_info.start_date));
        ui->tableWidgetr_Car->item(row,6)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,7,new QTableWidgetItem(stall_info.stop_date));
        ui->tableWidgetr_Car->item(row,7)->setTextAlignment(Qt::AlignCenter);
    }
    ui->label_Car_Total->setText(QString("车辆总数:%1辆").arg(stall_info_list.count()));
}

void MainWindow::on_pushButton_CarNoSearch_clicked()
{
    ui->tableWidgetr_Car->clear();

    ui->tableWidgetr_Car->setColumnCount(8);   //设置列数
    QStringList header;
    QString car_no=ui->lineEdit_CarNo->text().trimmed();
    header<<"序号"<<"车牌号"<<"类型"<<"车位"<<"联系人"<<"电话"<<"开始时间"<<"结束时间";
    ui->tableWidgetr_Car->setHorizontalHeaderLabels(header);
    ui->tableWidgetr_Car->verticalHeader()->setVisible(false);
    QList<car_stall_info> stall_info_list;
    stall_info_list=this->myDb->select_vehicle_info(&this->myDb->sqlite_db,car_no);
    ui->tableWidgetr_Car->setRowCount(stall_info_list.count());
    for(int row=0;row<stall_info_list.count();row++)
    {
        car_stall_info stall_info;
        stall_info=stall_info_list.at(row);
        ui->tableWidgetr_Car->setItem(row,0,new QTableWidgetItem(QString::number(row+1)));
        ui->tableWidgetr_Car->item(row,0)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,1,new QTableWidgetItem(stall_info.car_no));
        ui->tableWidgetr_Car->item(row,1)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,2,new QTableWidgetItem(stall_info.car_type));
        ui->tableWidgetr_Car->item(row,2)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,3,new QTableWidgetItem(stall_info.code_Id));
        ui->tableWidgetr_Car->item(row,3)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,4,new QTableWidgetItem(stall_info.person_name));
        ui->tableWidgetr_Car->item(row,4)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,5,new QTableWidgetItem(stall_info.person_tel));
        ui->tableWidgetr_Car->item(row,5)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,6,new QTableWidgetItem(stall_info.start_date));
        ui->tableWidgetr_Car->item(row,6)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidgetr_Car->setItem(row,7,new QTableWidgetItem(stall_info.stop_date));
        ui->tableWidgetr_Car->item(row,7)->setTextAlignment(Qt::AlignCenter);
    }
    ui->label_Car_Total->setText(QString("车辆总数:%1辆").arg(stall_info_list.count()));
}

void MainWindow::on_toolButton_SearchRecord_clicked()
{
    ui->dateTimeEdit_min->setDateTime(QDateTime::currentDateTime().addDays(-15));
    ui->dateTimeEdit_max->setDateTime(QDateTime::currentDateTime());
    QStringList header;
    QString min_time,max_time,car_no,car_type;
    ui->tableWidget_Record->clear();
    ui->tableWidget_Record->setColumnCount(6);   //设置列数
    car_no=ui->lineEdit_Record_CarNum->text().trimmed();
    car_type=ui->comboBox_Record_CarType->currentText().trimmed();
    min_time=ui->dateTimeEdit_min->text().trimmed();
    max_time=ui->dateTimeEdit_max->text().trimmed();
    header<<"序号"<<"车牌号"<<"类型"<<"入场时间"<<"出场时间"<<"传输状态";
    ui->tableWidget_Record->setHorizontalHeaderLabels(header);
    int p=ui->tableWidget_Record->width();
    ui->tableWidget_Record->setColumnWidth(0,p/6);
    ui->tableWidget_Record->setColumnWidth(1,p/6);
    ui->tableWidget_Record->setColumnWidth(2,p/6);
    ui->tableWidget_Record->setColumnWidth(3,p/6);
    ui->tableWidget_Record->setColumnWidth(4,p/6);
    ui->tableWidget_Record->setColumnWidth(5,p/6);
    ui->tableWidget_Record->setAlternatingRowColors(true);
    ui->tableWidget_Record->verticalHeader()->setVisible(false);
    ui->tableWidget_Record->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidget_Record->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget_Record->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->tableWidget_Record->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//去掉水平滚动条
    QList<car_record_info> record_info_list;
    record_info_list=this->myDb->select_record_info(&this->myDb->sqlite_db,car_no,car_type,min_time,max_time);
    ui->tableWidget_Record->setRowCount(record_info_list.count());
    for(int row=0;row<record_info_list.count();row++)
    {
        car_record_info record_info;
        record_info=record_info_list.at(row);
        ui->tableWidget_Record->setItem(row,0,new QTableWidgetItem(QString::number(row+1)));
        ui->tableWidget_Record->item(row,0)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_Record->setItem(row,1,new QTableWidgetItem(record_info.car_no));
        ui->tableWidget_Record->item(row,1)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_Record->setItem(row,2,new QTableWidgetItem(record_info.car_type));
        ui->tableWidget_Record->item(row,2)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_Record->setItem(row,3,new QTableWidgetItem(record_info.in_time));
        ui->tableWidget_Record->item(row,3)->setTextAlignment(Qt::AlignCenter);

        if(record_info.out_time.isEmpty()){
            ui->tableWidget_Record->setItem(row,4,new QTableWidgetItem("未出场"));
        }else{
            ui->tableWidget_Record->setItem(row,4,new QTableWidgetItem(record_info.out_time));
        }
        ui->tableWidget_Record->item(row,4)->setTextAlignment(Qt::AlignCenter);

        if(record_info.modife_flag==0){// modife_flag=0 未传
            ui->tableWidget_Record->setItem(row,5,new QTableWidgetItem("未传"));
        }else if(record_info.modife_flag==1){// modife_flag=1 已传
            ui->tableWidget_Record->setItem(row,5,new QTableWidgetItem("已传"));
        }

        ui->tableWidget_Record->item(row,5)->setTextAlignment(Qt::AlignCenter);
    }
    ui->label_Record_Total->setText(QString("车辆总数：%1辆 ").arg(record_info_list.count()));
}

void MainWindow::on_pushButton_RecordFind_clicked()
{
    QStringList header;
    QString min_time,max_time,car_no,car_type;
    ui->tableWidget_Record->clear();
    ui->tableWidget_Record->setColumnCount(6);   //设置列数
    min_time=ui->dateTimeEdit_min->text().trimmed();
    max_time=ui->dateTimeEdit_max->text().trimmed();
    car_no=ui->lineEdit_Record_CarNum->text().trimmed();
    car_type=ui->comboBox_Record_CarType->currentText().trimmed();
    header<<"序号"<<"车牌号"<<"类型"<<"入场时间"<<"出场时间"<<"传输状态";
    ui->tableWidget_Record->setHorizontalHeaderLabels(header);
    int p=ui->tableWidget_Record->width();
    ui->tableWidget_Record->setColumnWidth(0,p/6);
    ui->tableWidget_Record->setColumnWidth(1,p/6);
    ui->tableWidget_Record->setColumnWidth(2,p/6);
    ui->tableWidget_Record->setColumnWidth(3,p/6);
    ui->tableWidget_Record->setColumnWidth(4,p/6);
    ui->tableWidget_Record->setColumnWidth(5,p/6);
    ui->tableWidget_Record->setAlternatingRowColors(true);
    ui->tableWidget_Record->verticalHeader()->setVisible(false);
    ui->tableWidget_Record->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidget_Record->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget_Record->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->tableWidget_Record->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//去掉水平滚动条
    QList<car_record_info> record_info_list;
    record_info_list=this->myDb->select_record_info(&this->myDb->sqlite_db,car_no,car_type,min_time,max_time);
    ui->tableWidget_Record->setRowCount(record_info_list.count());
    for(int row=0;row<record_info_list.count();row++)
    {
        car_record_info record_info;
        record_info=record_info_list.at(row);
        ui->tableWidget_Record->setItem(row,0,new QTableWidgetItem(QString::number(row+1)));
        ui->tableWidget_Record->item(row,0)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_Record->setItem(row,1,new QTableWidgetItem(record_info.car_no));
        ui->tableWidget_Record->item(row,1)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_Record->setItem(row,2,new QTableWidgetItem(record_info.car_type));
        ui->tableWidget_Record->item(row,2)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_Record->setItem(row,3,new QTableWidgetItem(record_info.in_time));
        ui->tableWidget_Record->item(row,3)->setTextAlignment(Qt::AlignCenter);

        if(record_info.out_time.isEmpty()){
            ui->tableWidget_Record->setItem(row,4,new QTableWidgetItem("未出场"));
        }else{
            ui->tableWidget_Record->setItem(row,4,new QTableWidgetItem(record_info.out_time));
        }
        ui->tableWidget_Record->item(row,4)->setTextAlignment(Qt::AlignCenter);

        if(record_info.modife_flag==0){//未传
            ui->tableWidget_Record->setItem(row,5,new QTableWidgetItem("未传"));
        }else if(record_info.modife_flag==1){//已传
            ui->tableWidget_Record->setItem(row,5,new QTableWidgetItem("已传"));
        }
        ui->tableWidget_Record->item(row,5)->setTextAlignment(Qt::AlignCenter);
    }
    ui->label_Record_Total->setText(QString("车辆总数：%1辆 ").arg(record_info_list.count()));
}

void MainWindow::on_toolButton_SearchFeeRecord_clicked()
{
    ui->comboBox_FeeRecordUser->clear();
    ui->tableWidget_SrearchFeeRecord->clear();
    QStringList user_list=this->myDb->select_user(&this->myDb->sqlite_db);
    ui->comboBox_FeeRecordUser->insertItems(0,user_list);
    ui->dateTimeEdit_FeeRecordStart->setDateTime(QDateTime::currentDateTime().addYears(-1).addDays(-15));
    ui->dateTimeEdit_FeeRecordEnd->setDateTime(QDateTime::currentDateTime());
    QStringList header;
    ui->tableWidget_SrearchFeeRecord->setColumnCount(9);   //设置列数
    header<<"序号"<<"车牌号"<<"类型"<<"入场时间"<<"出场时间"<<"停车时长"<<"应收"<<"实收"<<"优惠";
    ui->tableWidget_SrearchFeeRecord->setHorizontalHeaderLabels(header);
    QString Car_No,Operator,min_time,max_time;
    Car_No=ui->lineEdit_FeeRecordCar->text().trimmed();
    Operator=ui->comboBox_FeeRecordUser->currentText();
    min_time=ui->dateTimeEdit_FeeRecordStart->text();
    max_time=ui->dateTimeEdit_FeeRecordEnd->text();

    int p=ui->tableWidget_SrearchFeeRecord->width();
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(0,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(1,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(2,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(3,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(4,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(5,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(6,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(7,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(8,p/9);
    ui->tableWidget_SrearchFeeRecord->setAlternatingRowColors(true);
    ui->tableWidget_SrearchFeeRecord->verticalHeader()->setVisible(false);
    ui->tableWidget_SrearchFeeRecord->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidget_SrearchFeeRecord->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget_SrearchFeeRecord->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->tableWidget_SrearchFeeRecord->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//去掉水平滚动条

    QList<car_record_info> record_info_list;
    record_info_list=this->myDb->select_Fee_info(&this->myDb->sqlite_db,Car_No,Operator,min_time,max_time);

    qDebug()<<"record_info_list.count()"<<record_info_list.count();

    ui->tableWidget_SrearchFeeRecord->setRowCount(record_info_list.count());
    float car_fee_should_count=0,car_fee_actual_count=0,car_fee_discount_count=0,cash_count=0;
    int car_discount_count=0,car_fee_count=0,car_cash_count=0;
    for(int row=0;row<record_info_list.count();row++)
    {
        car_record_info record_info;
        record_info=record_info_list.at(row);
        ui->tableWidget_SrearchFeeRecord->setItem(row,0,new QTableWidgetItem(QString::number(row+1)));
        ui->tableWidget_SrearchFeeRecord->item(row,0)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,1,new QTableWidgetItem(record_info.car_no));
        ui->tableWidget_SrearchFeeRecord->item(row,1)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,2,new QTableWidgetItem(record_info.car_type));
        ui->tableWidget_SrearchFeeRecord->item(row,2)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,3,new QTableWidgetItem(record_info.in_time));
        ui->tableWidget_SrearchFeeRecord->item(row,3)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,4,new QTableWidgetItem(record_info.out_time));
        ui->tableWidget_SrearchFeeRecord->item(row,4)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,5,new QTableWidgetItem(QString("%1小时%2分钟").arg(record_info.stall_time/60).arg(record_info.stall_time%60)));
        ui->tableWidget_SrearchFeeRecord->item(row,5)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,6,new QTableWidgetItem(QString::number(record_info.receivable)));
        ui->tableWidget_SrearchFeeRecord->item(row,6)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,7,new QTableWidgetItem(QString::number(record_info.actual_money)));
        ui->tableWidget_SrearchFeeRecord->item(row,7)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,8,new QTableWidgetItem(QString::number(record_info.discount)));
        ui->tableWidget_SrearchFeeRecord->item(row,8)->setTextAlignment(Qt::AlignCenter);
        if(record_info.receivable>0&&record_info.discount>0)//blue
        {
            car_discount_count++;
            ui->tableWidget_SrearchFeeRecord->item(row,6)->setTextColor(QColor(0,255,0));
            ui->tableWidget_SrearchFeeRecord->item(row,7)->setTextColor(QColor(0,255,0));
            ui->tableWidget_SrearchFeeRecord->item(row,8)->setTextColor(QColor(0,255,0));
        }else if(record_info.receivable>0&&record_info.actual_money==0&&record_info.discount==0)//red
        {
            car_fee_count++;
            ui->tableWidget_SrearchFeeRecord->item(row,6)->setTextColor(QColor(255,0,0));
            ui->tableWidget_SrearchFeeRecord->item(row,7)->setTextColor(QColor(255,0,0));
            ui->tableWidget_SrearchFeeRecord->item(row,8)->setTextColor(QColor(255,0,0));
        }
        if(record_info.pay_way==1)//(car_cash_count,cash_count)
        {
            car_cash_count++,
                    cash_count=cash_count+record_info.actual_money;
        }
    }
    for(int row=0;row<record_info_list.count();row++)
    {
        car_fee_should_count+=ui->tableWidget_SrearchFeeRecord->item(row,6)->text().toFloat();
        car_fee_actual_count+=ui->tableWidget_SrearchFeeRecord->item(row,7)->text().toFloat();
        car_fee_discount_count+=ui->tableWidget_SrearchFeeRecord->item(row,8)->text().toFloat();
    }
    ui->label_RecordCarNum->setText(QString::number(record_info_list.count()).append("辆"));
    ui->label_RecordFreeNum->setText(QString::number(car_discount_count).append("辆"));
    ui->label_RecordFreeCarNum->setText(QString::number(car_fee_count).append("辆"));
    ui->label_RecordCar->setText(QString::number(car_fee_should_count).append("元"));
    ui->label_RecordFree->setText(QString::number(car_fee_discount_count).append("元"));
    ui->label_RecordMoney->setText(QString::number(car_fee_actual_count).append("元"));
    ui->label_RecordFeeNum->setText(QString::number(car_cash_count).append("辆"));
    ui->label_RecordFee->setText(QString::number(cash_count).append("元"));
}

void MainWindow::on_pushButton_FeeRecordSelct_clicked()
{
    QStringList header;
    ui->tableWidget_SrearchFeeRecord->clear();
    ui->tableWidget_SrearchFeeRecord->setColumnCount(9);   //设置列数
    header<<"序号"<<"车牌号"<<"类型"<<"入场时间"<<"出场时间"<<"停车时长"<<"应收"<<"实收"<<"优惠";
    ui->tableWidget_SrearchFeeRecord->setHorizontalHeaderLabels(header);
    QString Car_No,Operator,min_time,max_time;
    Car_No=ui->lineEdit_FeeRecordCar->text().trimmed();
    Operator=ui->comboBox_FeeRecordUser->currentText();
    min_time=ui->dateTimeEdit_FeeRecordStart->text();
    max_time=ui->dateTimeEdit_FeeRecordEnd->text();

    int p=ui->tableWidget_SrearchFeeRecord->width();
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(0,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(1,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(2,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(3,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(4,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(5,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(6,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(7,p/9);
    ui->tableWidget_SrearchFeeRecord->setColumnWidth(8,p/9);
    ui->tableWidget_SrearchFeeRecord->setAlternatingRowColors(true);
    ui->tableWidget_SrearchFeeRecord->verticalHeader()->setVisible(false);
    ui->tableWidget_SrearchFeeRecord->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidget_SrearchFeeRecord->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget_SrearchFeeRecord->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->tableWidget_SrearchFeeRecord->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//去掉水平滚动条

    QList<car_record_info> record_info_list;
    record_info_list=this->myDb->select_Fee_info(&this->myDb->sqlite_db,Car_No,Operator,min_time,max_time);
    float car_fee_should_count=0,car_fee_actual_count=0,car_fee_discount_count=0,cash_count=0;
    int car_discount_count=0,car_fee_count=0,car_cash_count=0;
    ui->tableWidget_SrearchFeeRecord->setRowCount(record_info_list.count());
    for(int row=0;row<record_info_list.count();row++)
    {
        car_record_info record_info;
        record_info=record_info_list.at(row);
        ui->tableWidget_SrearchFeeRecord->setItem(row,0,new QTableWidgetItem(QString::number(row+1)));
        ui->tableWidget_SrearchFeeRecord->item(row,0)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,1,new QTableWidgetItem(record_info.car_no));
        ui->tableWidget_SrearchFeeRecord->item(row,1)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,2,new QTableWidgetItem(record_info.car_type));
        ui->tableWidget_SrearchFeeRecord->item(row,2)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,3,new QTableWidgetItem(record_info.in_time));
        ui->tableWidget_SrearchFeeRecord->item(row,3)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,4,new QTableWidgetItem(record_info.out_time));
        ui->tableWidget_SrearchFeeRecord->item(row,4)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,5,new QTableWidgetItem(QString("%1小时%2分钟").arg(record_info.stall_time/60).arg(record_info.stall_time%60)));
        ui->tableWidget_SrearchFeeRecord->item(row,5)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,6,new QTableWidgetItem(QString::number(record_info.receivable)));
        ui->tableWidget_SrearchFeeRecord->item(row,6)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,7,new QTableWidgetItem(QString::number(record_info.actual_money)));
        ui->tableWidget_SrearchFeeRecord->item(row,7)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_SrearchFeeRecord->setItem(row,8,new QTableWidgetItem(QString::number(record_info.discount)));
        ui->tableWidget_SrearchFeeRecord->item(row,8)->setTextAlignment(Qt::AlignCenter);
        if(record_info.receivable>0&&record_info.discount>0){//blue
            car_discount_count++;
            ui->tableWidget_SrearchFeeRecord->item(row,6)->setTextColor(QColor(0,255,0));
            ui->tableWidget_SrearchFeeRecord->item(row,7)->setTextColor(QColor(0,255,0));
            ui->tableWidget_SrearchFeeRecord->item(row,8)->setTextColor(QColor(0,255,0));
        }else if(record_info.receivable>0&&record_info.actual_money==0&&record_info.discount==0)
        {//red
            car_fee_count++;
            ui->tableWidget_SrearchFeeRecord->item(row,6)->setTextColor(QColor(255,0,0));
            ui->tableWidget_SrearchFeeRecord->item(row,7)->setTextColor(QColor(255,0,0));
            ui->tableWidget_SrearchFeeRecord->item(row,8)->setTextColor(QColor(255,0,0));
        }
        if(record_info.pay_way==1)
        {
            car_cash_count++,
                    cash_count+=record_info.actual_money;
        }
    }
    for(int row=0;row<record_info_list.count();row++){
        car_fee_should_count+=ui->tableWidget_SrearchFeeRecord->item(row,6)->text().toFloat();
        car_fee_actual_count+=ui->tableWidget_SrearchFeeRecord->item(row,7)->text().toFloat();
        car_fee_discount_count+=ui->tableWidget_SrearchFeeRecord->item(row,8)->text().toFloat();
    }
    ui->label_RecordCarNum->setText(QString::number(record_info_list.count()).append("辆"));
    ui->label_RecordFreeNum->setText(QString::number(car_discount_count).append("辆"));
    ui->label_RecordFreeCarNum->setText(QString::number(car_fee_count).append("辆"));
    ui->label_RecordCar->setText(QString::number(car_fee_should_count).append("元"));
    ui->label_RecordFree->setText(QString::number(car_fee_discount_count).append("元"));
    ui->label_RecordMoney->setText(QString::number(car_fee_actual_count).append("元"));
    ui->label_RecordFeeNum->setText(QString::number(car_cash_count).append("辆"));
    ui->label_RecordFee->setText(QString::number(cash_count).append("元"));
}

void MainWindow::on_pushButton_RecordOut_clicked()//通行记录导出
{
    QString filename = QFileDialog::getSaveFileName(this, tr("Excel file"), tr("通行记录表"),

                                                    tr("Files (*.xls *.xlsx)"));
    if (filename.isEmpty())
    {
        return;
    }
    excel.Open(filename);
    excel.SaveDataFrTable(ui->tableWidget_Record);
    excel.Close();
}

void MainWindow::on_pushButton_FeeRecordOut_clicked()//收费记录导出
{
    QString filename = QFileDialog::getSaveFileName(this, tr("Excel file"), tr("收费记录表"),

                                                    tr("Files (*.xls *.xlsx)"));
    if (filename.isEmpty())
    {
        return;
    }
    excel.Open(filename);
    excel.SaveDataFrTable(ui->tableWidget_SrearchFeeRecord);
    excel.Close();
}

void MainWindow::on_tableWidget_Record_clicked(const QModelIndex &index)
{
    QString car_no=index.sibling(index.row(),1).data().toString();
    QString car_type=index.sibling(index.row(),2).data().toString();
    QString car_in_time=index.sibling(index.row(),3).data().toString();
    QString car_out_time=index.sibling(index.row(),4).data().toString();
    qDebug()<<"on_tableWidget_Record_clicked"<<car_no<<car_type<<car_in_time<<car_out_time;
    ui->stackedWidget_Search->setCurrentIndex(3);
    ui->label_detail_carNum->setText(car_no);
    ui->label_detail_carType->setText(car_type);
    ui->label_detail_intime->setText(car_in_time);
    ui->label_detail_outtime->setText(car_out_time);
    car_record_info record_info=this->myDb->select_detail_record_Fee_info(&this->myDb->sqlite_db,car_no,car_type,car_in_time,car_out_time);

    ui->label_should_fee->setText(QString::number(record_info.receivable));
    ui->label_actual_fee->setText(QString::number(record_info.actual_money));
    ui->label_detail_fee_discount->setText(QString::number(record_info.discount));
    ui->label_detail_stoptime->setText(QString("%1小时%2分钟").arg(record_info.stall_time/60).arg(record_info.stall_time%60));

    QStringList setail_list=this->myDb->select_detail_record_info(&this->myDb->sqlite_db,car_no,car_type,car_in_time,car_out_time);
    QString in_image=setail_list.at(4);
    QString out_image=setail_list.at(5);
    in_image=in_image.left(10)+"/"+in_image;
    out_image=out_image.left(10)+"/"+out_image;

    ui->label_detail_inoperator->setText(setail_list.at(0));
    ui->label_detail_outoperator->setText(setail_list.at(1));
    ui->label_detail_psaastatus->setText(setail_list.at(2));
    if(setail_list.at(3).isEmpty())
        ui->label_detail_stall->setText("无");
    else ui->label_detail_stall->setText(setail_list.at(3));
    qDebug()<<"in_image"<<in_image<<"out_image"<<out_image;
    QFile my_infile(in_image);
    QFile my_outfile(out_image);
    inRecordPixmap=QPixmap(in_image);
    outRecordPixmap=QPixmap(out_image);
    if(my_infile.exists()){
        ui->label_RecordInPicture->setPixmap(inRecordPixmap);
    }else{
        ui->label_RecordInPicture->setPixmap(QPixmap(":/images/u2.png"));
    }
    if(my_outfile.exists()){
        ui->label_RecordOutPicture->setPixmap(outRecordPixmap);
    }else{
        ui->label_RecordOutPicture->setPixmap(QPixmap(":/images/u2.png"));
    }
    ui->pushButton_print_bills->setVisible(false);
}
void MainWindow::on_tableWidget_SrearchFeeRecord_clicked(const QModelIndex &index)
{
    QString car_no=index.sibling(index.row(),1).data().toString();
    QString car_type=index.sibling(index.row(),2).data().toString();
    QString car_in_time=index.sibling(index.row(),3).data().toString();
    QString car_out_time=index.sibling(index.row(),4).data().toString();
    QString car_stop_time=index.sibling(index.row(),5).data().toString();
    float car_fee_should=index.sibling(index.row(),6).data().toFloat();
    float car_fee_actual=index.sibling(index.row(),7).data().toFloat();
    float car_fee_discount=index.sibling(index.row(),8).data().toFloat();

    ui->stackedWidget_Search->setCurrentIndex(3);
    qDebug()<<car_no<<car_type<<car_in_time<<car_out_time<<car_stop_time<<car_fee_should<<car_fee_actual<<car_fee_discount;
    ui->label_detail_carNum->setText(car_no);
    ui->label_detail_carType->setText(car_type);
    ui->label_should_fee->setText(QString::number(car_fee_should));
    ui->label_actual_fee->setText(QString::number(car_fee_actual));
    ui->label_detail_fee_discount->setText(QString::number(car_fee_discount));
    ui->label_detail_stoptime->setText(car_stop_time);
    ui->label_detail_intime->setText(car_in_time);
    ui->label_detail_outtime->setText(car_out_time);
    QStringList setail_list=this->myDb->select_detail_record_info(&this->myDb->sqlite_db,car_no,car_type,car_in_time,car_out_time);

    QString in_image,out_image;
    in_image=setail_list.at(4);
    out_image=setail_list.at(5);
    in_image=in_image.left(10)+"/"+in_image;
    out_image=out_image.left(10)+"/"+out_image;
    ui->label_detail_inoperator->setText(setail_list.at(0));
    ui->label_detail_outoperator->setText(setail_list.at(1));
    ui->label_detail_psaastatus->setText(setail_list.at(2));
    if(setail_list.at(3).isEmpty())
        ui->label_detail_stall->setText("无");
    else ui->label_detail_stall->setText(setail_list.at(3));
    qDebug()<<"in_image"<<in_image<<"out_image"<<out_image;

    QFile my_infile(in_image);
    QFile my_outfile(out_image);
    inRecordPixmap=QPixmap(in_image);
    outRecordPixmap=QPixmap(out_image);
    if(my_infile.exists()){
        ui->label_RecordInPicture->setPixmap(inRecordPixmap);
    }else{
        ui->label_RecordInPicture->setPixmap(QPixmap(":/images/u2.png"));
    }
    if(my_outfile.exists()){
        ui->label_RecordOutPicture->setPixmap(outRecordPixmap);
    }else{
        ui->label_RecordOutPicture->setPixmap(QPixmap(":/images/u2.png"));
    }
    ui->pushButton_print_bills->setVisible(true);
}

/*******张超Start******/
void MainWindow::on_pushButton_SeatNew_clicked()
{
    seatDilog =new Seat(this->myDb);
    seatDilog->exec();
    tableWidget_Seat_Show();
}

void MainWindow::on_pushButton_SeatClear_clicked()
{
    this->myDb->deleteSeat(&this->myDb->sqlite_db);
    QMessageBox::information(this,QObject::trUtf8("提示"), QObject::trUtf8("车位信息删除成功"));
    tableWidget_Seat_Show();
}

void MainWindow::paintEvent(QPaintEvent *)//背景
{
    QPixmap pix(":/images/back.jpg");
    QPainter painter(this);
    int w = width();
    int h = height();
    painter.drawPixmap(0,0,w,h,pix);
}



void MainWindow::on_pushButton_OK_clicked()//确认收费
{ 
    CARNO.clear();
    CARINTIME.clear();
    //显示屏及语音提示
    if(Car_OutInfor.pass_num.isEmpty())
    {
        return;
    }else
    {
        bool res;
        ///bzero(&info,sizeof(info));
        displayData_t info;
        bzeroInfo(info);

        info.DispelayStr[2]=Car_OutVehicle;
        info.DispelayStr[3]="一路平安请出场";
        for(int i=1;i<4;i++)
        {
            info.audioStr.append(info.DispelayStr[i]);
        }
        this->cameraOut->socket_short_display(&info);

        qDebug()<<"out"<<Car_OutInfor.pass_num;
        this->myDb->writeCarOutLog(&this->myDb->sqlite_db,Camera_picOut,QString::number(Car_OutInfor.money),&Car_OutInfor);
    }
    timer_out->start(250);
    if(sysInfo->savePicture==1)
    {
        filelink->copyFileToDate(Camera_picOut.left(10),CAROUT,Camera_picOut);
    }
}
//张超start
void MainWindow::on_pushButton_FeeFreeOk_clicked()
{
    switch(QMessageBox::warning(this,QObject::trUtf8("提示"),QObject::trUtf8("是否修改收费规则?"),QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Cancel))
    {
    case QMessageBox::Ok:break;
    case QMessageBox::Cancel:
        return;
    }
    sysInfo->FreeTime=ui->comboBox_FeeLinFree->currentText();
    sysInfo->FreeTime2=ui->comboBox_FeeTanFree->currentText();
    if(tool_FeeFreeBool)
    {
        sysInfo->LoseFreeTime=1;
    }else{
        sysInfo->LoseFreeTime=0;
    }
    if(tool_Fee24Bool)
    {
        sysInfo->AddDayTime=1;
    }else{
        sysInfo->AddDayTime=0;
    }
    sysInfo->SettingSave();
    QMessageBox::information(NULL, QString("提示"), QString("收费规则修改完成"));
}

void MainWindow::on_pushButton_SysRestart_clicked()
{
    switch(QMessageBox::warning(this,QObject::trUtf8("提示"),QObject::trUtf8("是否修改收费规则?"),QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Cancel))
    {
    case QMessageBox::Ok:break;
    case QMessageBox::Cancel:
        return;
    }
    sysInfo->resetSetting();
    sysInfo->readSetting();
    QMessageBox::information(NULL, QString("提示"), QString("恢复出厂设置完成"));
    sysTemReset();
}

bool MainWindow::carInSys(QString car_no)
{
    qDebug()<<"carInSys(QString car_no)"<<car_no<<sysInfo->park_camera<<sysInfo->park_type<<sysInfo->tempCarIn;
    displayData_t info;
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }

    if(sysInfo->park_camera==0)//没有开启应急模式
    {
        if(sysInfo->park_type==0)//空位为零不允许进入
        {
            info.audioStr = "空位为零不允许进入  ";
            info.DispelayStr[3] = info.audioStr;
            this->cameraIn->socket_short_display(&info);
            return  false;
        }else{
            if(sysInfo->tempCarIn==1)//临时车入场确认
            {
                info.audioStr = QString("临时车%1 ").arg(car_no);
                info.DispelayStr[3] = info.audioStr;
                this->cameraIn->socket_short_display(&info);
                return false;
            }else{
                info.DispelayStr[3] = QString("%1欢迎入场  ").arg(car_no);
                info.audioStr = info.DispelayStr[3];
                this->cameraIn->socket_short_display(&info);
                return true;
            }
        }
    }else{
        info.audioStr = QString("%1请入场  ").arg(car_no);
        info.DispelayStr[3] = info.audioStr;
        this->cameraIn->socket_short_display(&info);
        return true;
    }
}

/**********张超end2017-10-17****************/
void MainWindow::on_toolButton_NoCar_clicked()//查找场内无牌车
{
    QString car_type="临时车";
    QString car_no="无牌";
    find_car(0,car_no,car_type,1,2);//第一个参数为0，时间无效
}

void MainWindow::on_toolButton_1Hour_clicked()//查找场内0-1小时车
{
    QString car_type=ui->comboBox_CarType->currentText().trimmed();
    QString car_no=ui->lineEdit_Find_CarNo->text().trimmed();
    find_car(1,car_no,car_type,0,1);//第一个参数为1，时间有效
}

void MainWindow::on_toolButton_1_2Hour_clicked()//查找场内1-2小时车
{
    QString car_type=ui->comboBox_CarType->currentText().trimmed();
    QString car_no=ui->lineEdit_Find_CarNo->text().trimmed();
    find_car(1,car_no,car_type,1,2);//第一个参数为1，时间有效
}

void MainWindow::on_toolButton_2_4Hour_clicked()//查找场内2-4小时车
{
    QString car_type=ui->comboBox_CarType->currentText().trimmed();
    QString car_no=ui->lineEdit_Find_CarNo->text().trimmed();
    find_car(1,car_no,car_type,2,4);//第一个参数为1，时间有效
}

void MainWindow::on_toolButton_24Hour_clicked()//查找场内24小时车
{
    QString car_type=ui->comboBox_CarType->currentText().trimmed();
    QString car_no=ui->lineEdit_Find_CarNo->text().trimmed();
    find_car(1,car_no,car_type,0,24);//第一个参数为1，时间有效
}
void MainWindow::on_toolButton_10_clicked()//场内车辆
{
    QString car_type=ui->comboBox_CarType->currentText().trimmed();
    QString car_no=ui->lineEdit_Find_CarNo->text().trimmed();
    find_car(2,car_no,car_type,0,24);//第一个参数为2，时间无效，车牌号类型有效
}
void MainWindow::on_toolButton_CarInPark_clicked()//选车出厂
{
    QString car_type=ui->comboBox_CarType->currentText().trimmed();
    QString car_no=ui->lineEdit_Find_CarNo->text().trimmed();
    find_car(2,car_no,car_type,0,24);//第一个参数为2，时间无效，车牌号类型有效
}
void MainWindow::find_car(int flag,QString car_no,QString car_type,int min_time,int max_time)
{
    //查找数据库  场内车辆
    ui->tableWidget_CarIn->clear();
    CARNO.clear();
    ui->tableWidget_CarIn->setColumnCount(3);   //设置列数
    QStringList header;
    header<<"入场时间"<<"车牌号";
    ui->tableWidget_CarIn->setHorizontalHeaderLabels(header);
    int p=ui->tableWidget_CarIn->width();
    ui->tableWidget_CarIn->setColumnWidth(0,p/2);
    ui->tableWidget_CarIn->setColumnWidth(1,p/2);
    ui->tableWidget_CarIn->setColumnWidth(2,0);

    ui->tableWidget_CarIn->setAlternatingRowColors(true);
    ui->tableWidget_CarIn->verticalHeader()->setVisible(false);
    ui->tableWidget_CarIn->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidget_CarIn->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget_CarIn->setSelectionMode ( QAbstractItemView::SingleSelection);
    ui->tableWidget_CarIn->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//去掉水平滚动条

    QList<car_in_find> car_in_find_list=this->myDb->select_in_car(&this->myDb->sqlite_db,flag,car_no,car_type,min_time,max_time);
    ui->tableWidget_CarIn->setRowCount(car_in_find_list.count());
    for(int row=0;row<car_in_find_list.count();row++)
    {
        car_in_find car_in_info;
        car_in_info=car_in_find_list.at(row);
        ui->tableWidget_CarIn->setItem(row,0,new QTableWidgetItem(car_in_info.in_time));
        ui->tableWidget_CarIn->item(row,0)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_CarIn->setItem(row,1,new QTableWidgetItem(car_in_info.car_no));
        ui->tableWidget_CarIn->item(row,1)->setTextAlignment(Qt::AlignCenter);
        ui->tableWidget_CarIn->setItem(row,2,new QTableWidgetItem(car_in_info.in_image));
        ui->tableWidget_CarIn->item(row,2)->setTextAlignment(Qt::AlignCenter);
    }
}

void MainWindow::on_tableWidget_CarIn_clicked(const QModelIndex &index)
{
    CARNO=index.sibling(index.row(),1).data().toString();
    CARINTIME=index.sibling(index.row(),0).data().toString();
    Car_OutInfor.inImage=index.sibling(index.row(),2).data().toString();
    QString in_pic=Car_OutInfor.inImage;
    in_pic=in_pic.left(10)+"/"+in_pic;
    QFile my_infile(in_pic);
    if(my_infile.exists()){
        ui->label_ParkInPic->setPixmap(QPixmap(in_pic));
        InParkPixmap=QPixmap(in_pic);
    }else{
        ui->label_ParkInPic->setPixmap(QPixmap(":/images/u2.png"));
        InParkPixmap=QPixmap(QPixmap(":/images/u2.png"));
    }
}

void MainWindow::on_toolButton_ParkInOK_clicked()//手动出厂-确认出厂
{
    qDebug()<<CARNO<<CARINTIME;
    if(CARNO.isEmpty()){
        QMessageBox::about(this,"提示","请选择出场车辆！\n");
        return;
    }else{
        /*********************选择车牌，时间，计算收费，返回主界面**************************/
        QString in_pic=this->myDb->select_in_pic(&this->myDb->sqlite_db,CARNO,CARINTIME);
        QFile my_infile(in_pic);
        if(my_infile.exists()){
            ui->label_PictureIn->setPixmap(QPixmap(in_pic));
        }else{
            ui->label_PictureIn->setPixmap(QPixmap(":/images/u2.png"));
        }
        // ui->pushButton_carIn->setText(CARNO);
        ui->stackedWidget_Window->setCurrentIndex(0);
        CarOutFlag=true;
        if(!sysInfo->cameraOutIp.isEmpty() && ui->stackedWidget_cameraOut->currentIndex()==1)
        {
            this->cameraOut->socket_short_request(REQUEST_TARGET);
        }
        ui->pushButton_carOut->setText(CARNO);
        ui->pushButton_CarNo->setText(CARNO);
        //      CARNO.clear();
        //      CARINTIME.clear();
    }
}

//张超
void MainWindow::on_toolButton_NoCarIn_clicked()//无牌入场
{
    WuPaiCarFlag=true;
    if(!sysInfo->cameraInIp.isEmpty() && ui->stackedWidget_cameraIn->currentIndex()==1)
    {
        this->cameraIn->socket_short_request(REQUEST_TARGET);
    }
}

void MainWindow::WuPaiCarRecive()
{
    HandCarIn("无牌");
}

void MainWindow::on_listWidget_FreeFee_clicked(const QModelIndex &index)
{
    QString str= index.sibling(index.row(),0).data().toString();
    QRegExp rx("(\\d+)");  // 匹配数字
    int pos = 0;
    while ((pos = rx.indexIn(str, pos)) != -1) {
        Car_OutInfor.discount=QString::number(rx.cap(0).toInt());
        pos += rx.matchedLength();
    }
    qDebug()<<str<<Car_OutInfor.discount;
    ListShow();
    if(!Car_OutInfor.pass_num.isEmpty())
    {
        ui->textBrowser_CarStatus->clear();
        float actal;
        if(Car_OutInfor.receivable.toFloat()>Car_OutInfor.discount.toFloat())
        {
            actal=Car_OutInfor.receivable.toFloat()-Car_OutInfor.discount.toFloat();
            Car_OutInfor.actual_money=QString("%1").arg(actal);
        }else{
            Car_OutInfor.actual_money=QString::number(0);
        }
        ui->textBrowser_CarStatus->clear();
        ui->textBrowser_CarStatus->append(QString("车类型:%1").arg(Car_OutInfor.car_type));
        ui->textBrowser_CarStatus->append(QString("停车时长:%1").arg(Car_OutInfor.parkTime));
        ui->textBrowser_CarStatus->append(QString("收费金额:%1元").arg(Car_OutInfor.actual_money));
        ui->textBrowser_CarStatus->append(QString("优惠金额:%1元").arg(Car_OutInfor.discount));
        displayData_t info;
        info.DispelayStr[3]=QString("收费%1元").arg(Car_OutInfor.actual_money);
        info.audioStr= info.DispelayStr[3];
        this->cameraOut->socket_short_display(&info);
    }
}
